diff --git a/modules/core/src/main/scala/SchemaModule.scala b/modules/core/src/main/scala/SchemaModule.scala index d601ace..d460523 100644 --- a/modules/core/src/main/scala/SchemaModule.scala +++ b/modules/core/src/main/scala/SchemaModule.scala @@ -2,26 +2,9 @@ package scalaz package schema -import monocle.Iso - -trait HFunctor[H[_[_], _]] { - def hmap[F[_], G[_]](nt: F ~> G): H[F, ?] ~> H[G, ?] -} - -final case class Fix[F[_[_], _], A](unFix: F[Fix[F, ?], A]) - -final case class HEnvT[E, F[_[_], _], G[_], I](ask: E, fa: F[G, I]) +import recursion._ -object HEnvT { - - implicit def hfunctor[E, F[_[_], _]](implicit F: HFunctor[F]): HFunctor[HEnvT[E, F, ?[_], ?]] = - new HFunctor[HEnvT[E, F, ?[_], ?]] { - - def hmap[M[_], N[_]](nt: M ~> N) = new (HEnvT[E, F, M, ?] ~> HEnvT[E, F, N, ?]) { - def apply[I](fm: HEnvT[E, F, M, I]) = HEnvT(fm.ask, F.hmap(nt)(fm.fa)) - } - } -} +import monocle.Iso trait Realisation { type Prim[A] @@ -175,18 +158,18 @@ final case class ComposedInterpreter[F[_], G[_], H[_]](underlying: Interpreter[F } class CataInterpreter[S[_[_], _], F[_]]( - algebra: SchemaF.HAlgebra[S, F] + algebra: HAlgebra[S, F] )(implicit ev: HFunctor[S]) extends Interpreter[Fix[S, ?], F] { - final override val interpret = SchemaF.cataNT(algebra) + final override val interpret = cataNT(algebra) } class HyloInterpreter[S[_[_], _], F[_], G[_]]( - coalgebra: SchemaF.HCoalgebra[S, G], - algebra: SchemaF.HAlgebra[S, F] + coalgebra: HCoalgebra[S, G], + algebra: HAlgebra[S, F] )(implicit ev: HFunctor[S]) extends Interpreter[G, F] { - final override val interpret = SchemaF.hyloNT(coalgebra, algebra) + final override val interpret = hyloNT(coalgebra, algebra) } object SchemaF { @@ -256,33 +239,6 @@ object SchemaF { def toSchema = Fix(new :*:(l.toSchema, r.toSchema)) } - - // Schema syntax - - /////////////////////// - // Schema operations - /////////////////////// - - type HAlgebra[F[_[_], _], G[_]] = F[G, ?] ~> G - type HCoalgebra[F[_[_], _], G[_]] = G ~> F[G, ?] - - def cataNT[S[_[_], _], F[_]]( - alg: HAlgebra[S, F] - )(implicit S: HFunctor[S]): (Fix[S, ?] ~> F) = - new (Fix[S, ?] ~> F) { self => - - def apply[A](f: Fix[S, A]): F[A] = - alg.apply[A](S.hmap(self)(f.unFix)) - } - - def hyloNT[S[_[_], _], F[_], G[_]](coalgebra: HCoalgebra[S, F], algebra: HAlgebra[S, G])( - implicit S: HFunctor[S] - ): F ~> G = new (F ~> G) { self => - - def apply[A](fa: F[A]): G[A] = - algebra(S.hmap(self)(coalgebra(fa))) - } - } trait SchemaModule[R <: Realisation] { diff --git a/modules/generic/src/main/scala/GenericAlgebra.scala b/modules/generic/src/main/scala/GenericAlgebra.scala index 83a6735..a200489 100644 --- a/modules/generic/src/main/scala/GenericAlgebra.scala +++ b/modules/generic/src/main/scala/GenericAlgebra.scala @@ -4,9 +4,9 @@ package schema package generic -trait GenericSchemaModule[R <: Realisation] extends SchemaModule[R] { +import recursion._ - import SchemaF._ +trait GenericSchemaModule[R <: Realisation] extends SchemaModule[R] { def covariantTargetFunctor[H[_]]( primNT: R.Prim ~> H, diff --git a/modules/generic/src/main/scala/ShowModule.scala b/modules/generic/src/main/scala/ShowModule.scala index 1a91e0c..2aa4332 100644 --- a/modules/generic/src/main/scala/ShowModule.scala +++ b/modules/generic/src/main/scala/ShowModule.scala @@ -4,8 +4,9 @@ package schema package generic +import recursion._ + trait ShowModule[R <: Realisation] extends GenericSchemaModule[R] { - import SchemaF._ implicit val showDecidableInstance: Decidable[Show] = new Decidable[Show] { override def choose2[Z, A1, A2](a1: => Show[A1], a2: => Show[A2])(f: Z => A1 \/ A2): Show[Z] = diff --git a/modules/play-json/src/main/scala/PlayJsonModule.scala b/modules/play-json/src/main/scala/PlayJsonModule.scala index 9870ed5..3e59987 100644 --- a/modules/play-json/src/main/scala/PlayJsonModule.scala +++ b/modules/play-json/src/main/scala/PlayJsonModule.scala @@ -4,6 +4,8 @@ package schema package play.json +import recursion._ + import Scalaz._ import Liskov._ import _root_.play.api.libs.json._