Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created June 26, 2018 03:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/19c9bb8c3afd08175762957880c57500 to your computer and use it in GitHub Desktop.
Save xuwei-k/19c9bb8c3afd08175762957880c57500 to your computer and use it in GitHub Desktop.
scalaVersion := "2.12.6"
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")
package generic_cont_example
trait ~> [-F[_], +G[_]] {
def run[A](fa: F[A]): G[A]
}
final case class ContT[M[_], A](x: λ[a => A => M[a]] ~> M) {
def map[B](f: A => B): ContT[M, B] =
ContT[M, B](
λ[~>[λ[a => B => M[a]], M]].run(k =>
x.run(a => k(f(a)))
)
)
def flatMap[B](f: A => ContT[M, B]): ContT[M, B] =
ContT[M, B](
λ[~>[λ[a => B => M[a]], M]].run(k =>
x.run(a => f(a).x.run(k))
)
)
def run[R](f: A => M[R]): M[R] =
x.run(f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment