I am trying to understand a higher order polymophism in scala by implementing a very simple interface that describes a monad, but I am facing a problem that I really don't understand.
I implemented the same with C ++, and the code looks like this:
When trying to do the same with scala I crash:
class Value[T](val value: T) class Monad[Container[T]] { def pure[A](a: A): Container[A] = Container[A](a) } object Main { def main(args: Array[String]): Unit = { val m = new Monad[Value] m.pure(1) } }
The compiler complains:
[raichoo@lain:Scala]:434> scalac highorder.scala highorder.scala:5: error: not found: value Container Container[A](a) ^ one error found
What am I doing wrong here? There seems to be a fundamental concept that I don't seem to understand about scala constructors.
Regards, raichoo
polymorphism types scala monads
raichoo
source share