Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Encodings generated by @algebra for `Expr`
trait Expr[A] {
def num(value: Long): A;
def mul(l: A, r: A): A
};
trait ExprFAlgebra {
import scalaz.Isomorphism.$less$tilde$greater;
import scalaz.$tilde$greater;
sealed abstract class Σ[_];
case class Num[A](value: Long) extends Σ[A];
case class Mul[A](l: A, r: A) extends Σ[A];
object Σ {
import scalaz.Functor;
import org.hablapps.azucar.DerivingFunctor._;
implicit val functorInstance = Functor[Σ]
};
trait FAlgebra[X] extends matryoshka.Algebra[Σ, X];
object FAlgebra {
def apply[A](implicit FA: FAlgebra[A]) = FA
};
val iso: <~>[Expr, FAlgebra] = {
final class $anon extends <~>[Expr, FAlgebra] {
def to: ~>[Expr, FAlgebra] = {
final class $anon extends ~>[Expr, FAlgebra] {
def apply[A](algebra: Expr[A]): FAlgebra[A] = {
final class $anon extends FAlgebra[A] {
def apply(fx: Σ[A]): A = fx match {
case Num((value @ _)) => algebra.num(value)
case Mul((l @ _), (r @ _)) => algebra.mul(l, r)
}
};
new $anon()
}
};
new $anon()
};
def from: ~>[FAlgebra, Expr] = {
final class $anon extends ~>[FAlgebra, Expr] {
def apply[A](falgebra: FAlgebra[A]): Expr[A] = {
final class $anon extends Expr[A] {
def num(value: Long): A = falgebra(Num(value));
def mul(l: A, r: A): A = falgebra(Mul(l, r))
};
new $anon()
}
};
new $anon()
}
};
new $anon()
};
implicit def fromFAlgebra[A](implicit FAlgebra: FAlgebra[A]): Expr[A] = iso.from(FAlgebra);
implicit def fromOAlgebra[A](implicit OAlgebra: Expr[A]): FAlgebra[A] = iso.to(OAlgebra)
};
object Expr extends ExprFAlgebra {
def apply[A](implicit ev: Expr[A]) = ev
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment