Created
October 17, 2011 21:01
-
-
Save retronym/1293796 to your computer and use it in GitHub Desktop.
path-dependent-type-monad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object test { | |
trait M[X[_]] { | |
def flatMap[A, B](a: X[A])(f: A => X[B]): X[B] | |
} | |
class ParsersW[P <: Parsers](val parsers: P) { | |
type Parser[A] = parsers.Parser[A] | |
val m: M[Parser] = new M[Parser] { | |
def flatMap[A, B](a: Parser[A])(f: A => Parser[B]): Parser[B] = a.flatMap(f) | |
} | |
} | |
trait Parsers { | |
trait Parser[Y] { | |
def flatMap[B](f: Y => Parser[B]): Parser[B] | |
} | |
} | |
def parserM[P <: Parsers](parsers: P) | |
: M[_1.parsers.Parser] forSome { val _1: ParsersW[P] } | |
= new ParsersW[P](parsers).m | |
object testParsers extends Parsers | |
val x = parserM[testParsers.type](testParsers) | |
x: M[testParsers.Parser] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment