Skip to content

Instantly share code, notes, and snippets.

@nanne007
Created April 17, 2014 07:27
Show Gist options
  • Save nanne007/10960834 to your computer and use it in GitHub Desktop.
Save nanne007/10960834 to your computer and use it in GitHub Desktop.
Continuation Monad in Scala
case class M[+A](in: (A => Any) => Any);
def unit[A](x: A) = M { k: (A => Any) => k(x) }
def bind[A, B](m: M[A], f: A => M[B]): M[B] =
M { k: (B => Any) =>
m.in { x: A =>
f(x).in(k)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment