From 899920a0a083ed4ff71b340c86dbee387b973336 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 10 Jun 2010 08:14:50 -0400 Subject: [PATCH] conversions --- tasks/src/test/scala/TListCompileTest.scala | 17 ----------------- tasks/{ => src/test/scala}/Test.scala | 0 util/collection/HList.scala | 6 ++++++ util/collection/MList.scala | 9 ++++++++- util/collection/TypeFunctions.scala | 7 +++++++ 5 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 tasks/src/test/scala/TListCompileTest.scala rename tasks/{ => src/test/scala}/Test.scala (100%) diff --git a/tasks/src/test/scala/TListCompileTest.scala b/tasks/src/test/scala/TListCompileTest.scala deleted file mode 100644 index 068ec2ca0..000000000 --- a/tasks/src/test/scala/TListCompileTest.scala +++ /dev/null @@ -1,17 +0,0 @@ -package xsbt - -import HLists._ -import Task._ - -/** This test just verifies that the HList support compiles.*/ -object TListCompileTest -{ - val n = Task(1) - val s = Task("3") - val t = Task(true) - val mapped = (n :: s :: t :: TNil) map { case n :: s :: t :: HNil => n } - val bound = (n :: s :: t :: TNil) bind { case n :: s :: t :: HNil => (Task(n*4) :: Task("Hi " + t) :: TNil).join } - - val plusOne = mapped map { _ + 1 } - val forkN = plusOne bind { count => (0 until count) fork { i => Task(println(i)) } join } -} \ No newline at end of file diff --git a/tasks/Test.scala b/tasks/src/test/scala/Test.scala similarity index 100% rename from tasks/Test.scala rename to tasks/src/test/scala/Test.scala diff --git a/util/collection/HList.scala b/util/collection/HList.scala index a475c1194..a1e595eeb 100644 --- a/util/collection/HList.scala +++ b/util/collection/HList.scala @@ -25,4 +25,10 @@ final case class HCons[H, T <: HList](head : H, tail : T) extends HList 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) +} + +object HList +{ + // contains no type information: not even A + implicit def fromList[A](list: Traversable[A]): HList = ((HNil: HList) /: list) ( (hl,v) => HCons(v, hl) ) } \ No newline at end of file diff --git a/util/collection/MList.scala b/util/collection/MList.scala index b350858c3..7adfc1568 100644 --- a/util/collection/MList.scala +++ b/util/collection/MList.scala @@ -41,4 +41,11 @@ sealed class MNil extends MList[Nothing] def toList = Nil } -object MNil extends MNil \ No newline at end of file +object MNil extends MNil + + +object MList +{ + implicit def fromTCList[A[_]](list: Traversable[A[_]]): MList[A] = ((MNil: MList[A]) /: list) ( (hl,v) => MCons(v, hl) ) + implicit def fromList[A](list: Traversable[A]): MList[Const[A]#Apply] = ((MNil: MList[Const[A]#Apply]) /: list) ( (hl,v) => MCons[A, hl.type, Const[A]#Apply](v, hl) ) +} \ No newline at end of file diff --git a/util/collection/TypeFunctions.scala b/util/collection/TypeFunctions.scala index 00a6fc772..942a00d72 100644 --- a/util/collection/TypeFunctions.scala +++ b/util/collection/TypeFunctions.scala @@ -13,6 +13,10 @@ trait TypeFunctions final val left = new (Id ~> P1of2[Left, Nothing]#Flip) { def apply[T](t: T) = Left(t) } final val right = new (Id ~> P1of2[Right, Nothing]#Apply) { def apply[T](t: T) = Right(t) } final val some = new (Id ~> Some) { def apply[T](t: T) = Some(t) } + + implicit def toFn1[A,B](f: A => B): Fn1[A,B] = new Fn1[A,B] { + def ∙[C](g: C => A) = f compose g + } } object TypeFunctions extends TypeFunctions @@ -29,4 +33,7 @@ object ~> import TypeFunctions._ val Id: Id ~> Id = new (Id ~> Id) { def apply[T](a: T): T = a } implicit def tcIdEquals: (Id ~> Id) = Id +} +trait Fn1[A, B] { + def ∙[C](g: C => A): C => B } \ No newline at end of file