diff options
author | Martin Odersky <odersky@gmail.com> | 2014-06-18 18:20:14 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-06-18 18:21:07 +0200 |
commit | 7f721438b5bccc8ca9dd68cef273c8cac8199e1a (patch) | |
tree | a619fb770fee578354c7fca1f1c30c68f0d542d0 /tests/pos/hk.scala | |
parent | 388d9a889c6929699e879a307dc80145b906390a (diff) | |
download | dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.tar.gz dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.tar.bz2 dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.zip |
Handling higher-kinded types with lambdas
Switch to the new scheme where higher-kinded types (and also some polymorphic
type aliases) are represented as instances of Lambda traits.
Diffstat (limited to 'tests/pos/hk.scala')
-rw-r--r-- | tests/pos/hk.scala | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/tests/pos/hk.scala b/tests/pos/hk.scala index f2f10bbfb..461c6e386 100644 --- a/tests/pos/hk.scala +++ b/tests/pos/hk.scala @@ -1,34 +1,55 @@ import language.higherKinds +object hk0 { + + class Base { + type Rep[T] + val strRep: Rep[String] + } + + class Sub extends Base { + type Rep[T] = T + val strRep = "abc" + val sr: Rep[String] = "" + } + + class Functor[F[_]] { + def map[A, B](f: A => B): F[A] => F[B] + } + val ml: Functor[List] = ??? + val mx = ml + val mm: (Int => Boolean) => List[Int] => List[Boolean] = mx.map +} + object higherKinded { - + type Untyped = Null class Tree[-T >: Untyped] { type ThisType[-U >: Untyped] <: Tree[U] def withString(s: String): ThisType[String] = withString(s) } - + class Ident[-T >: Untyped] extends Tree[T] { type ThisType[-U] = Ident[U] } - + val id = new Ident[Integer] - + val y = id.withString("abc") - + val z: Ident[String] = y - + val zz: tpd.Tree = y - + abstract class Instance[T >: Untyped] { type Tree = higherKinded.Tree[T] } - + object tpd extends Instance[String] - + def transform(tree: Tree[String]) = { - val tree1 = tree.withString("") + val tree1 = tree.withString("") tree1: Tree[String] } |