Skip to content

Instantly share code, notes, and snippets.

@wemrysi
Last active August 29, 2015 14:02
Show Gist options
  • Save wemrysi/0a04b1f2a4b36e89655c to your computer and use it in GitHub Desktop.
Save wemrysi/0a04b1f2a4b36e89655c to your computer and use it in GitHub Desktop.
runFree
def runFree[S[+_], M[_]](f: S ~> M)(implicit M: Monad[M]): ({type λ[α] = Free[S, α]})#λ ~> M =
new (({type λ[α] = Free[S, α]})#λ ~> M) {
def apply[A](fr: Free[S, A]) = fr.foldMap[M, A](f)
}
def runFreeC[S[+_], M[_]](f: S ~> M)(implicit M: Monad[M]): ({type λ[α] = FreeC[S, α]})#λ ~> M =
new (({type λ[α] = FreeC[S, α]})#λ ~> M) {
def apply[A](fr: FreeC[S, A]) = fr.runM[M, A](coyo => M.map(f(coyo.fi))(coyo.k))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment