mirror of https://github.com/sbt/sbt.git
variance fixes, inference fixes with Result hierarchy
This commit is contained in:
parent
75a784d5ec
commit
ec19be6152
|
|
@ -1,3 +1,6 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
trait Incomplete
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import Node._
|
||||
|
|
@ -5,40 +8,28 @@ import Types._
|
|||
|
||||
trait Node[A[_], T]
|
||||
{
|
||||
type Inputs <: MList[Id]
|
||||
type Inputs <: MList[A]
|
||||
type Results <: Inputs#Map[Result]
|
||||
|
||||
def inputs: Inputs#Map[A]
|
||||
val inputs: Inputs
|
||||
def unitDependencies: Iterable[A[_]]
|
||||
|
||||
def work(results: Results, units: Iterable[Incomplete]): Either[A[T], T]
|
||||
}
|
||||
|
||||
object Node
|
||||
{
|
||||
type Result[T] = Either[Throwable, T]
|
||||
|
||||
def pure[T](f: => T): PureNode[T]= map[Id, T, MNil](MNil, Nil)((_,_) => f)
|
||||
|
||||
def map[A[_], T, Inputs0 <: MList[Id]](inputs0: Inputs0#Map[A], deps0: Iterable[A[_]])(work0: (Inputs0#Map[Result], Iterable[Incomplete]) => T):
|
||||
def map[A[_], T, Inputs0 <: MList[A]](inputs0: Inputs0, deps0: Iterable[A[_]])(work0: (Inputs0#Map[Result], Iterable[Incomplete]) => T):
|
||||
Node[A,T] { type Inputs = Inputs0; type Results = Inputs0#Map[Result] } =
|
||||
new Node[A,T] {
|
||||
type Inputs = Inputs0
|
||||
type Results = Inputs0#Map[Result]
|
||||
def inputs = inputs0
|
||||
def unitDependencies = deps0
|
||||
def work(results: Results, units: Iterable[Incomplete]) = Right(work0(results, units))
|
||||
}
|
||||
new Node[A,T] {
|
||||
type Inputs = Inputs0
|
||||
type Results = Inputs0#Map[Result]
|
||||
val inputs = inputs0
|
||||
def unitDependencies = deps0
|
||||
def work(results: Results, units: Iterable[Incomplete]) = Right(work0(results, units))
|
||||
}
|
||||
|
||||
type PureNode[T] = Node[Id, T] { type Inputs = MNil; type Results = MNil }
|
||||
type WorkResult[T] = Either[Id[T], T]
|
||||
val pureResults = new ~>[PureNode, WorkResult] { def apply[T](t: PureNode[T] ) = t.work( MNil, Nil ) }
|
||||
}
|
||||
object Test
|
||||
{
|
||||
val a = pure(3)
|
||||
val b = pure(true)
|
||||
val c = pure("asdf")
|
||||
val i3 = a :^: b :^: c :^: MNil
|
||||
|
||||
val d = map[PureNode, String, i3.Map[Id]](i3, Nil) { case (a :^: b :^: c :^: MNil, Seq()) => a + " " + b + " " + c }
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
// used instead of Either[Throwable, T] for type inference
|
||||
sealed trait Result[+T]
|
||||
final case class Exc(cause: Throwable) extends Result[Nothing]
|
||||
final case class Value[+T](value: T) extends Result[T]
|
||||
|
|
@ -1,22 +1,28 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import Types._
|
||||
|
||||
sealed trait HList
|
||||
{
|
||||
type ToM[M[_]] <: MList[M]
|
||||
type Up <: MList[Id]
|
||||
def up: Up
|
||||
}
|
||||
sealed trait HNil extends HList
|
||||
{
|
||||
type Up = MNil[Id]
|
||||
type ToM[M[_]] = MNil
|
||||
type Up = MNil
|
||||
def up = MNil
|
||||
def :+: [G](g: G): G :+: HNil = HCons(g, this)
|
||||
}
|
||||
object HNil extends HNil
|
||||
final case class HCons[H, T <: HList](head : H, tail : T) extends HList
|
||||
{
|
||||
type Up = MCons[H, T#Up, Id]
|
||||
def up = MCons[H,T#Up, Id](head, tail.up)
|
||||
type ToM[M[_]] = MCons[H, tail.ToM[M], M]
|
||||
type Up = MCons[H, tail.Up, Id]
|
||||
def up = MCons[H,tail.Up, Id](head, tail.up)
|
||||
def :+: [G](g: G): G :+: H :+: T = HCons(g, this)
|
||||
}
|
||||
|
|
@ -1,42 +1,33 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import Types._
|
||||
|
||||
sealed trait MList[M[_]]
|
||||
sealed trait MList[+M[_]]
|
||||
{
|
||||
type Map[N[_]] <: MList[N]
|
||||
def map[N[_]](f: M ~> N): Map[N]
|
||||
|
||||
type Down <: HList
|
||||
def down: Down
|
||||
|
||||
def toList: List[M[_]]
|
||||
}
|
||||
final case class MCons[H, T <: MList[M], M[_]](head: M[H], tail: T) extends MList[M]
|
||||
final case class MCons[H, +T <: MList[M], +M[_]](head: M[H], tail: T) extends MList[M]
|
||||
{
|
||||
type Down = M[H] :+: T#Down
|
||||
def down = HCons(head, tail.down)
|
||||
|
||||
type Map[N[_]] = MCons[H, T#Map[N], N]
|
||||
type Map[N[_]] = MCons[H, tail.Map[N], N]
|
||||
def map[N[_]](f: M ~> N) = MCons( f(head), tail.map(f) )
|
||||
|
||||
def :^: [G](g: M[G]): MCons[G, MCons[H, T, M], M] = MCons(g, this)
|
||||
def :^: [N[X] >: M[X], G](g: N[G]): MCons[G, MCons[H, T, N], N] = MCons(g, this)
|
||||
|
||||
def toList = head :: tail.toList
|
||||
}
|
||||
sealed class MNil[M[_]] extends MList[M]
|
||||
sealed class MNil extends MList[Nothing]
|
||||
{
|
||||
type Down = HNil
|
||||
def down = HNil
|
||||
|
||||
type Map[N[_]] = MNil[N]
|
||||
def map[N[_]](f: M ~> N): MNil[N] = new MNil[N]
|
||||
type Map[N[_]] = MNil
|
||||
def map[N[_]](f: Nothing ~> N) = MNil
|
||||
|
||||
def :^: [H](h: M[H]): MCons[H, MNil[M], M] = MCons(h, this)
|
||||
def :^: [M[_], H](h: M[H]): MCons[H, MNil, M] = MCons(h, this)
|
||||
|
||||
def toList = Nil
|
||||
}
|
||||
object MNil extends MNil[Id]
|
||||
{
|
||||
implicit def apply[N[_]]: MNil[N] = new MNil[N]
|
||||
}
|
||||
object MNil extends MNil
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
trait TypeFunctions
|
||||
|
|
@ -7,11 +10,11 @@ trait TypeFunctions
|
|||
trait P1of2[M[_,_], A] { type Apply[B] = M[A,B] }
|
||||
trait Down[M[_]] { type Apply[B] = Id[M[B]] }
|
||||
|
||||
trait ~>[A[_], B[_]]
|
||||
trait ~>[-A[_], +B[_]]
|
||||
{
|
||||
def apply[T](a: A[T]): B[T]
|
||||
}
|
||||
def Id: Id ~> Id =
|
||||
new ~>[Id, Id] { def apply[T](a: T): T = a }
|
||||
new (Id ~> Id) { def apply[T](a: T): T = a }
|
||||
}
|
||||
object TypeFunctions extends TypeFunctions
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2010 Mark Harrah
|
||||
*/
|
||||
package sbt
|
||||
|
||||
object Types extends TypeFunctions
|
||||
|
|
|
|||
Loading…
Reference in New Issue