Skip to content

Instantly share code, notes, and snippets.

@emilypi
Created December 15, 2017 20:52
Show Gist options
  • Save emilypi/e962e2bb4e21f77d00ab8a176b6a10d0 to your computer and use it in GitHub Desktop.
Save emilypi/e962e2bb4e21f77d00ab8a176b6a10d0 to your computer and use it in GitHub Desktop.
Cows go Muuu
package cohomolo.gy.generalized
import scalaz.Prelude.{<~<, IsCovariant}
import scalaz.data.{As, Identity, ~>, ∀}
//final case class Mu[F[_]](unMu: Algebra[F, ?] ~> Identity)
trait MuModule {
type Mu[F[_]]
def mu[F[_]](f: F[Mu[F]]): Mu[F]
def unMu[F[_]](f: Mu[F] )(implicit ev: Algebra[F, ?]): Algebra[F, ?] ~> Identity
def subst[G[_[_[_]]]](g: G[λ[α[_] => α[Mu[α]]]]): G[Mu]
def liftLiskov[F[_], G[_]](ev: ∀[λ[α => F[α] <~< G[α]]])(implicit F: IsCovariant[F]): Mu[F] <~< Mu[G]
}
private[generalized] object MuImpl extends MuModule {
type Mu[F[_]] = F[Mu[F]]
def mu[F[_]](f: F[Mu[F]]): Mu[F] = f
def unMu[F[_]](f: Mu[F] )(implicit ev: Algebra[F, ?] ~> Identity): Algebra[F, ?] ~> Identity = ev
def subst[G[_[_[_]]]](g: G[λ[α[_] => α[Mu[α]]]]): G[Mu] = g
def liftLiskov[F[_], G[_]](ev: ∀[λ[α => F[α] <~< G[α]]])(implicit F: IsCovariant[F]): Mu[F] <~< Mu[G] =
As.unsafeForce
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment