diff --git a/modules/core/src/main/scala/SchemaModule.scala b/modules/core/src/main/scala/SchemaModule.scala index 896b335..d80aec2 100644 --- a/modules/core/src/main/scala/SchemaModule.scala +++ b/modules/core/src/main/scala/SchemaModule.scala @@ -161,23 +161,23 @@ trait Interpreter[Prim[_], SumTermId, ProductTermId, F[_]] { * A natural transformation that will transform a schema for any type `A` * into an `F[A]`. */ - def interpret: Schema.FSchema[Prim, SumTermId, ProductTermId, ?] ~> F + def interpret: SchemaF.FSchema[Prim, SumTermId, ProductTermId, ?] ~> F } object SchemaF { implicit def schemaHFunctor[Prim[_], SumTermId, ProductTermId] = - new HFunctor[Schema[Prim, SumTermId, ProductTermId, ?[_], ?]] { + new HFunctor[SchemaF[Prim, SumTermId, ProductTermId, ?[_], ?]] { def hmap[F[_], G[_]](nt: F ~> G) = - new (Schema[Prim, SumTermId, ProductTermId, F, ?] ~> Schema[ + new (SchemaF[Prim, SumTermId, ProductTermId, F, ?] ~> SchemaF[ Prim, SumTermId, ProductTermId, G, ? ]) { - def apply[A](fa: Schema[Prim, SumTermId, ProductTermId, F, A]) = fa.hmap(nt) + def apply[A](fa: SchemaF[Prim, SumTermId, ProductTermId, F, A]) = fa.hmap(nt) } } @@ -264,6 +264,8 @@ trait SchemaModule[R <: Realisation] { val R: R + import SchemaF._ + type RInterpreter[F[_]] = Interpreter[R.Prim, R.SumTermId, R.ProductTermId, F] type RSchema[F[_], A] = SchemaF[R.Prim, R.SumTermId, R.ProductTermId, F, A] diff --git a/modules/play-json/src/main/scala/PlayJsonModule.scala b/modules/play-json/src/main/scala/PlayJsonModule.scala index 09de750..be64f50 100644 --- a/modules/play-json/src/main/scala/PlayJsonModule.scala +++ b/modules/play-json/src/main/scala/PlayJsonModule.scala @@ -11,7 +11,7 @@ import _root_.play.api.libs.functional.syntax._ trait PlayJsonModule[R <: Realisation] extends SchemaModule[R] { - import Schema._ + import SchemaF._ type LabelledSchema[A] = (Boolean, FSchema[R.Prim, R.SumTermId, R.ProductTermId, A]) diff --git a/modules/tests/src/main/scala/GenModuleExamples.scala b/modules/tests/src/main/scala/GenModuleExamples.scala index 1507363..ab60c5c 100644 --- a/modules/tests/src/main/scala/GenModuleExamples.scala +++ b/modules/tests/src/main/scala/GenModuleExamples.scala @@ -15,7 +15,7 @@ trait PrimToGen { case JsonSchema.JsonString => arbitrary[String] case JsonSchema.JsonNumber => arbitrary[BigDecimal] case JsonSchema.JsonBool => arbitrary[Boolean] - case JsonSchema.JsonNull => arbitrary[Null] + case JsonSchema.JsonNull => arbitrary[Unit] } } diff --git a/modules/tests/src/main/scala/GenericGenModule.scala b/modules/tests/src/main/scala/GenericGenModule.scala index effc7cd..a58ced9 100644 --- a/modules/tests/src/main/scala/GenericGenModule.scala +++ b/modules/tests/src/main/scala/GenericGenModule.scala @@ -32,8 +32,8 @@ trait GenericGenModule[R <: Realisation] extends GenericSchemaModule[R] { implicit final def algebra( implicit primNT: R.Prim ~> Gen - ): HAlgebra[RSchema, Gen] = - covariantTargetFunctor[Gen]( + ): RInterpreter[Gen] = new Interpreter[R.Prim, R.SumTermId, R.ProductTermId, Gen] { + private val alg = covariantTargetFunctor[Gen]( primNT, λ[Gen ~> λ[X => Gen[List[X]]]](x => Gen.listOf(x)), λ[RProductTerm[Gen, ?] ~> Gen](gen => gen.schema), @@ -41,4 +41,6 @@ trait GenericGenModule[R <: Realisation] extends GenericSchemaModule[R] { Gen.const(()) ) + def interpret: Schema ~> Gen = cataNT(alg) + } } diff --git a/modules/tests/src/main/scala/PlayJsonExamples.scala b/modules/tests/src/main/scala/PlayJsonExamples.scala index ea09587..3ff2cc3 100644 --- a/modules/tests/src/main/scala/PlayJsonExamples.scala +++ b/modules/tests/src/main/scala/PlayJsonExamples.scala @@ -50,7 +50,6 @@ object PlayJsonExamples { def tests[T](harness: Harness[T]): T = { import harness._ - import Schema._ import module._ import JsonSchema._ diff --git a/modules/tests/src/main/scala/ShowExamples.scala b/modules/tests/src/main/scala/ShowExamples.scala index a214ab6..a43880b 100644 --- a/modules/tests/src/main/scala/ShowExamples.scala +++ b/modules/tests/src/main/scala/ShowExamples.scala @@ -9,10 +9,11 @@ import generic._ object ShowExamples { - import JsonSchema._ - val showModule = new TestModule with ShowModule[JsonSchema.type] { + import SchemaF._ + import JsonSchema._ + val primToShowNT = new (JsonSchema.Prim ~> Show) { def apply[A](fa: JsonSchema.Prim[A]): Show[A] = @@ -20,9 +21,14 @@ object ShowExamples { case JsonNumber => Show.showFromToString[BigDecimal] case JsonBool => Show.showFromToString[Boolean] case JsonString => Show.shows[String](s => s""""$s"""") - case JsonNull => Show.shows[Null](_ => "null") + case JsonNull => Show.shows[Unit](_ => "null") } } + + implicit val interpreter = new Interpreter[R.Prim, R.SumTermId, R.ProductTermId, Show] { + private val alg = showAlgebra(primToShowNT, identity[String], identity[String]) + def interpret: Schema ~> Show = cataNT(alg) + } } def tests[T](harness: Harness[T]): T = { @@ -33,8 +39,6 @@ object ShowExamples { test("commons Show Instance") { () => { - implicit val alg = showAlgebra(primToShowNT, identity[String], identity[String]) - val testCases: List[(Person, String)] = List( Person(null, None) -> """(name = ("null"), role = (()))""", Person("Alfred", None) -> """(name = ("Alfred"), role = (()))""",