Ka Ter
unread,May 14, 2013, 8:36:57 AM5/14/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scala-l...@googlegroups.com
Hi,
I have problems understanding Scala's type system. Why does the
following code not compile in the line 'val z = ...'?
trait Unary[U[_], A]
case class A[T](t: T)
case class B[I[_], A](i: I[A]) extends Unary[({type O[X] = B[I, X]})#O, A]
def unary[MA <: Unary[U, A], U[_], A](ma: MA with Unary[U, A]): U[A] =
ma.asInstanceOf[U[A]]
val a = A(5)
val b = B(a)
val z = unary(b)
I get the error message: Multiple markers at this line
- type mismatch; found : B[A(in method
monadicAndMonadicStackSelection),Int] required: MA with
Unary[U,A(in method unary)]
- no type parameters for method unary: (ma: MA with Unary[U,A])U[A]
exist so that it can be applied to
arguments (B[A,Int]) --- because --- argument expression's type is
not compatible with formal parameter type;
found : B[A,Int] required: ?MA with Unary[?U,?A]
I don't understand why Scala cannot match the types. B is of type Unary.
I expect the type of z to be ({type O[X] = B[A, X})#O[Int]. I know that
I can achieve that using scalaz's Unapply type class, but I don't
understand why my solution should not work either.
Any thoughts?
--
Best Regards
Ka Ter