Rewrite to function syntax

This commit is contained in:
Dale Wijnand 2017-10-18 19:10:42 -05:00
parent fb17cc393f
commit f662fdda8e
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
8 changed files with 16 additions and 17 deletions

View File

@ -27,7 +27,7 @@ trait AList[K[L[x]]] {
}
object AList {
type Empty = AList[({ type l[L[x]] = Unit })#l]
type Empty = AList[ConstK[Unit]#l]
/** AList for Unit, which represents a sequence that is always empty.*/
val empty: Empty = new Empty {
@ -37,7 +37,7 @@ object AList {
def traverse[M[_], N[_], P[_]](in: Unit, f: M ~> (N P)#l)(implicit np: Applicative[N]): N[Unit] = np.pure(())
}
type SeqList[T] = AList[({ type l[L[x]] = List[L[T]] })#l]
type SeqList[T] = AList[λ[L[x] => List[L[T]]]]
/** AList for a homogeneous sequence. */
def seq[T]: SeqList[T] = new SeqList[T] {
@ -67,7 +67,7 @@ object AList {
override def toList[M[_]](k: KL[M]) = k.toList
}
type Single[A] = AList[({ type l[L[x]] = L[A] })#l]
type Single[A] = AList[λ[L[x] => L[A]]]
/** AList for a single value. */
def single[A]: Single[A] = new Single[A] {
@ -76,7 +76,7 @@ object AList {
def traverse[M[_], N[_], P[_]](a: M[A], f: M ~> (N P)#l)(implicit np: Applicative[N]): N[P[A]] = f(a)
}
type ASplit[K[L[x]], B[x]] = AList[({ type l[L[x]] = K[(L B)#l] })#l]
type ASplit[K[L[x]], B[x]] = AList[λ[L[x] => K[(L B)#l]]]
/** AList that operates on the outer type constructor `A` of a composition `[x] A[B[x]]` for type constructors `A` and `B`*/
def asplit[K[L[x]], B[x]](base: AList[K]): ASplit[K, B] = new ASplit[K, B] {

View File

@ -204,7 +204,7 @@ abstract class EvaluateSettings[Scope] {
new MixedNode[ConstK[Unit]#l, T]((), _ => f(), AList.empty)
private[this] def single[S, T](in: INode[S], f: S => T): INode[T] =
new MixedNode[({ type l[L[x]] = L[S] })#l, T](in, f, AList.single[S])
new MixedNode[λ[L[x] => L[S]], T](in, f, AList.single[S])
private[this] final class BindNode[S, T](in: INode[S], f: S => INode[T]) extends INode[T] {
protected def dependsOn = in :: Nil

View File

@ -31,8 +31,7 @@ trait IMap[K[_], V[_]] extends (K ~> V) with RMap[K, V] {
def remove[T](k: K[T]): IMap[K, V]
def mapValue[T](k: K[T], init: V[T], f: V[T] => V[T]): IMap[K, V]
def mapValues[V2[_]](f: V ~> V2): IMap[K, V2]
def mapSeparate[VL[_], VR[_]](f: V ~> ({ type l[T] = Either[VL[T], VR[T]] })#l)
: (IMap[K, VL], IMap[K, VR])
def mapSeparate[VL[_], VR[_]](f: V ~> λ[T => Either[VL[T], VR[T]]]): (IMap[K, VL], IMap[K, VR])
}
trait PMap[K[_], V[_]] extends (K ~> V) with RMap[K, V] {
@ -69,7 +68,7 @@ object IMap {
def mapValues[V2[_]](f: V ~> V2) =
new IMap0[K, V2](backing.mapValues(x => f(x)))
def mapSeparate[VL[_], VR[_]](f: V ~> ({ type l[T] = Either[VL[T], VR[T]] })#l) = {
def mapSeparate[VL[_], VR[_]](f: V ~> λ[T => Either[VL[T], VR[T]]]) = {
val mapped = backing.iterator.map {
case (k, v) =>
f(v) match {

View File

@ -101,14 +101,14 @@ trait Init[Scope] {
def bind[S, T](in: Initialize[S])(f: S => Initialize[T]): Initialize[T] = new Bind(f, in)
def map[S, T](in: Initialize[S])(f: S => T): Initialize[T] =
new Apply[({ type l[L[x]] = L[S] })#l, T](f, in, AList.single[S])
new Apply[λ[L[x] => L[S]], T](f, in, AList.single[S])
def app[K[L[x]], T](inputs: K[Initialize])(f: K[Id] => T)(
implicit alist: AList[K]
): Initialize[T] = new Apply[K, T](f, inputs, alist)
def uniform[S, T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] =
new Apply[({ type l[L[x]] = List[L[S]] })#l, T](f, inputs.toList, AList.seq[S])
new Apply[λ[L[x] => List[L[S]]], T](f, inputs.toList, AList.seq[S])
/**
* The result of this initialization is the validated `key`.
@ -560,7 +560,7 @@ trait Init[Scope] {
def zip[S](o: Initialize[S]): Initialize[(T, S)] = zipTupled(o)(idFun)
def zipWith[S, U](o: Initialize[S])(f: (T, S) => U): Initialize[U] = zipTupled(o)(f.tupled)
private[this] def zipTupled[S, U](o: Initialize[S])(f: ((T, S)) => U): Initialize[U] =
new Apply[({ type l[L[x]] = (L[T], L[S]) })#l, U](f, (this, o), AList.tuple2[T, S])
new Apply[λ[L[x] => (L[T], L[S])], U](f, (this, o), AList.tuple2[T, S])
/** A fold on the static attributes of this and nested Initializes. */
private[sbt] def processAttributes[S](init: S)(f: (S, AttributeMap) => S): S

View File

@ -441,7 +441,7 @@ object Scoped {
)
private[this] def onTasks[T](f: K[Task] => Task[T]): App[T] =
Def.app[({ type l[L[x]] = K[(L Task)#l] })#l, Task[T]](inputs)(f)(AList.asplit[K, Task](a))
Def.app[λ[L[x] => K[(L Task)#l]], Task[T]](inputs)(f)(AList.asplit[K, Task](a))
def flatMap[T](f: Fun[Id, Task[T]]): App[T] = onTasks(_.flatMap(convert(f)))
def flatMapR[T](f: Fun[Result, Task[T]]): App[T] = onTasks(_.flatMapR(convert(f)))

View File

@ -58,7 +58,7 @@ object Transform {
}
def uniform[T, D](tasks: Seq[Task[D]])(f: Seq[Result[D]] => Either[Task[T], T]): Node[Task, T] =
toNode[T, ({ type l[L[x]] = List[L[D]] })#l](tasks.toList)(f)(AList.seq[D])
toNode[T, λ[L[x] => List[L[D]]]](tasks.toList)(f)(AList.seq[D])
def toNode[T, k[L[x]]](inputs: k[Task])(f: k[Result] => Either[Task[T], T])(
implicit a: AList[k]): Node[Task, T] = new Node[Task, T] {

View File

@ -118,7 +118,7 @@ trait TaskExtra {
}
final implicit def multT2Task[A, B](in: (Task[A], Task[B])) =
multInputTask[({ type l[L[x]] = (L[A], L[B]) })#l](in)(AList.tuple2[A, B])
multInputTask[λ[L[x] => (L[A], L[B])]](in)(AList.tuple2[A, B])
final implicit def multInputTask[K[L[X]]](tasks: K[Task])(implicit a: AList[K]): MultiInTask[K] =
new MultiInTask[K] {
@ -248,7 +248,7 @@ object TaskExtra extends TaskExtra {
}
def reducePair[S](a: Task[S], b: Task[S], f: (S, S) => S): Task[S] =
multInputTask[({ type l[L[x]] = (L[S], L[S]) })#l]((a, b))(AList.tuple2[S, S]) map f.tupled
multInputTask[λ[L[x] => (L[S], L[S])]]((a, b))(AList.tuple2[S, S]) map f.tupled
def anyFailM[K[L[x]]](implicit a: AList[K]): K[Result] => Seq[Incomplete] = in => {
val incs = failuresM(a)(in)

View File

@ -11,9 +11,9 @@ import sbt.internal.util.AList
object Test extends std.TaskExtra {
def t2[A, B](a: Task[A], b: Task[B]) =
multInputTask[({ type l[L[x]] = (L[A], L[B]) })#l]((a, b))(AList.tuple2)
multInputTask[λ[L[x] => (L[A], L[B])]]((a, b))(AList.tuple2)
def t3[A, B, C](a: Task[A], b: Task[B], c: Task[C]) =
multInputTask[({ type l[L[x]] = (L[A], L[B], L[C]) })#l]((a, b, c))(AList.tuple3)
multInputTask[λ[L[x] => (L[A], L[B], L[C])]]((a, b, c))(AList.tuple3)
val a = task(3)
val b = task[Boolean](sys.error("test"))