Last active
June 11, 2018 14:55
-
-
Save yanns/d2a275462f8381e4eb953a2e13b16496 to your computer and use it in GitHub Desktop.
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
type Algebra[F[_], A] = F[A] => A | |
def cata[F[_], R, A](algebra: Algebra[F, A], out: R ⇒ F[R])(r: R)(implicit F: Functor[F]): A = | |
algebra(F.map(cata(algebra, out))(out(r))) | |
type Coalgebra[F[_], A] = A => F[A] | |
def ana[F[_], R, A](coalgebra: Coalgebra[F, A], in: F[R] ⇒ R)(a: A)(implicit F: Functor[F]): R = | |
in(F.map(ana(coalgebra, in))(coalgebra(a))) | |
def hylo[F[_], A, B](coalgebra: Coalgebra[F, A], algebra: Algebra[F, B]) | |
(a: A)(implicit F: Functor[F]): B = | |
algebra(F.map(hylo(coalgebra, algebra))(coalgebra(a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment