Skip to content

Instantly share code, notes, and snippets.

@retronym
Created October 17, 2011 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save retronym/1293796 to your computer and use it in GitHub Desktop.
Save retronym/1293796 to your computer and use it in GitHub Desktop.
path-dependent-type-monad
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