Ka Ter
unread,May 11, 2012, 10:09:32 AM5/11/12Sign 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 sca...@googlegroups.com
Hi,
I'm trying to implement some variation of monads (I call it monadics)
without type classes. I come to the point that the Scala compiler can
infere the necessary type and I'm wondering if there is any hint to
achieve this.
In the following example (reduced to functor map method) I try to wrap
an IdentityT by an IdentityT but there is a compiler error in the main
method. But when I provide the necessary type lambda per hand then it
works. Why can the compiler not see that an IdentityT is a Monadic, too?
Any ideas how I get this example to work?
PS: I tried something also using the scalaz library without success. Now
i reduced the type class overhead in order to see where the problem is
trait Monadic[A, M[_]]
{
def map[B](f: A => B): M[B] with Monadic[B, M]
}
case class Identity[A](val value: A) extends Monadic[A, Identity]
{
def map[B](f: A => B): Identity[B] = new Identity(f(value))
}
case class IdentityT[A, M[_]](val pool: Monadic[A, M]) extends
Monadic[A, ({type T[X] = IdentityT[X, M]})#T]
{
def map[B](f: A => B): IdentityT[B, M] = new IdentityT(pool.map(f))
}
object Main
{
def main(args: Array[String]): Unit =
{
val a = Identity(5)
val at = new IdentityT(a)
// val att = new IdentityT(at) // **** Compiler error
val att = new IdentityT[Int, ({type T[X] = IdentityT[X,
Identity]})#T](at) // This works
println(att)
}
}
--
Best Regards
Ka Ter