Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait R[+A] { self =>
- type In
- def apply(in: In): A
- def map[B](f: A => B): R[B] = new R[B] {
- type In = self.In
- def apply(in: In) = f(self(in))
- }
- def flatMap[B](f: A => R[B] { type In = self.In }): R[B] = new R[B] {
- type In = self.In
- def apply(in: In): B = f(self(in))(in)
- }
- }
- def foo[I, A](a: A): R[A] = new R[A] {
- type In = I
- def apply(in: In): A = a
- }
- //
- // compiles
- //
- val a: R[String] = foo[Int, String]("b").map(_ + "a")
- // does not compile
- //
- // Error:(20, 53) type mismatch;
- // found : A$A58.this.AA[String]
- // required: A$A58.this.AA[?]{type R = A$A58.this.AA[String]#R}
- // foo[Int, String]("a").flatMap(x => foo[Int, String](x));}
- //
- val b: R[String] = a.flatMap(x => foo[Int, String](x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement