diff --git a/util/collection/HList.scala b/util/collection/HList.scala index b36f68955..a475c1194 100644 --- a/util/collection/HList.scala +++ b/util/collection/HList.scala @@ -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) } \ No newline at end of file diff --git a/util/collection/MList.scala b/util/collection/MList.scala index 981056823..58d2724c3 100644 --- a/util/collection/MList.scala +++ b/util/collection/MList.scala @@ -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] -} \ No newline at end of file +object MNil extends MNil diff --git a/util/collection/TypeFunctions.scala b/util/collection/TypeFunctions.scala index 9a6d96b14..95fb8ae9e 100644 --- a/util/collection/TypeFunctions.scala +++ b/util/collection/TypeFunctions.scala @@ -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 \ No newline at end of file diff --git a/util/collection/Types.scala b/util/collection/Types.scala index 40987e257..de468216d 100644 --- a/util/collection/Types.scala +++ b/util/collection/Types.scala @@ -1,3 +1,6 @@ +/* sbt -- Simple Build Tool + * Copyright 2010 Mark Harrah + */ package sbt object Types extends TypeFunctions