From 5bc3124a835e7f0b427bb8358b457547e2dbf212 Mon Sep 17 00:00:00 2001 From: Daniel Slapman Date: Sun, 28 Jul 2024 14:42:21 +0200 Subject: [PATCH] Fix all unimplementeds --- build.sbt | 2 +- src/main/scala-3/tc/Representable.scala | 4 ++-- src/main/scala-3/tc/derived/craft.scala | 12 +++++++----- src/main/scala-3/tc/derived/representable.scala | 12 +++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/build.sbt b/build.sbt index 76883c6..145373f 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -val scala3Version = "3.3.1" +val scala3Version = "3.3.3" name := "shalter" version := "0.0.7" diff --git a/src/main/scala-3/tc/Representable.scala b/src/main/scala-3/tc/Representable.scala index bd4d207..76fbaf5 100644 --- a/src/main/scala-3/tc/Representable.scala +++ b/src/main/scala-3/tc/Representable.scala @@ -24,7 +24,7 @@ trait RepresentableK[U[_[_]]] extends ApplicativeK[U]: tabulate([A] => (rep: Rep[U, A]) => f[A](rep(left) , rep(right))) object RepresentableK: - inline def derived[U[_[_]] <: Product]: RepresentableK[U] = deriveRepresentable + inline def derived[U[_[_]] <: Product : ApplyK]: RepresentableK[U] = deriveRepresentable trait TraversableK[U[_[_]]] extends FunctorK[U]: extension[F[_], G[+_], H[_]](uf: U[F]) @@ -43,4 +43,4 @@ trait Craft[U[_[_]]] extends RepresentableK[U] with TraversableK[U]: craft[G, H]([A] => (frep: Rep[U, A]) => f(frep(uf))) object Craft: - inline def derived[U[f[_]] <: Product]: Craft[U] = deriveCraft + inline def derived[U[f[_]] <: Product: ApplyK]: Craft[U] = deriveCraft diff --git a/src/main/scala-3/tc/derived/craft.scala b/src/main/scala-3/tc/derived/craft.scala index 29f0f27..871f3eb 100644 --- a/src/main/scala-3/tc/derived/craft.scala +++ b/src/main/scala-3/tc/derived/craft.scala @@ -3,13 +3,15 @@ package tc.derived import tc.* import cats.* import cats.data.Tuple2K +import cats.tagless.ApplyK +import cats.tagless.syntax.all.* import cats.syntax.all.* import hkd.* import scala.compiletime.* import scala.deriving.* -inline def deriveCraft[U[f[_]] <: Product]: Craft[U] = +inline def deriveCraft[U[f[_]] <: Product: ApplyK]: Craft[U] = val pack = craftPack[U].toArray new Craft[U] { def craft[F[+_]: Applicative, G[_]](gain: [A] => Rep[U, A] => F[G[A]]): F[U[G]] = summonFrom { @@ -30,9 +32,9 @@ inline def deriveCraft[U[f[_]] <: Product]: Craft[U] = case _ => error("can handle only case classes at the moment") } - override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[[Z] =>> Tuple2K[F, G, Z]] = ??? + override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[[Z] =>> Tuple2K[F, G, Z]] = af.productK(ag) - override def mapK[F[_], G[_]](af: U[F])(fk: F ~> G): U[G] = ??? + override def mapK[F[_], G[_]](af: U[F])(fk: F ~> G): U[G] = af.mapK(fk) } @@ -76,9 +78,9 @@ given monoCraft[X]: Craft[[F[_]] =>> F[X]] with //def craft[F[+_] : Applicative, G[_]](gain: [A] => Rep[[F] =>> F[X], A] => F[G[A]]): F[G[X]] = ??? - def productK[F[_], G[_]](af: F[X], ag: G[X]): Tuple2K[F, G, X] = ??? + def productK[F[_], G[_]](af: F[X], ag: G[X]): Tuple2K[F, G, X] = Tuple2K(af, ag) - def mapK[F[_], G[_]](af: F[X])(fk: F ~> G): G[X] = ??? + def mapK[F[_], G[_]](af: F[X])(fk: F ~> G): G[X] = fk.apply(af) diff --git a/src/main/scala-3/tc/derived/representable.scala b/src/main/scala-3/tc/derived/representable.scala index 6c73d85..1aa2ea0 100644 --- a/src/main/scala-3/tc/derived/representable.scala +++ b/src/main/scala-3/tc/derived/representable.scala @@ -2,13 +2,15 @@ package tc.derived import cats.arrow.FunctionK import cats.data.Tuple2K +import cats.tagless.ApplyK +import cats.tagless.syntax.all.* import tc.* import hkd.* import scala.compiletime.* import scala.deriving.* -inline def deriveRepresentable[U[_[_]] <: Product]: RepresentableK[U] = +inline def deriveRepresentable[U[_[_]] <: Product : ApplyK]: RepresentableK[U] = val pack = repPack[U].toArray new RepresentableK[U] { def tabulate[F[_]](gain: [A] => Rep[U, A] => F[A]) = summonFrom { @@ -25,9 +27,9 @@ inline def deriveRepresentable[U[_[_]] <: Product]: RepresentableK[U] = case _ => error("can handle only case classes at the moment") } - def mapK[F[_], G[_]](af: U[F])(fk: FunctionK[F, G]): U[G] = ??? + override def mapK[F[_], G[_]](af: U[F])(fk: FunctionK[F, G]): U[G] = af.mapK(fk) - override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[[Z] =>> Tuple2K[F, G, Z]] = ??? + override def productK[F[_], G[_]](af: U[F], ag: U[G]): U[[Z] =>> Tuple2K[F, G, Z]] = af.productK(ag) } @@ -70,6 +72,6 @@ given monoRepresentable[X]: RepresentableK[[F[_]] =>> F[X]] with def tabulate[G[_]](gain: [A] => ([F[_]] => F[X] => F[A]) => G[A]): G[X] = gain([G[_]] => (x: G[X]) => x) - def mapK[F[_], G[_]](af: F[X])(fk: FunctionK[F, G]): G[X] = ??? + def mapK[F[_], G[_]](af: F[X])(fk: FunctionK[F, G]): G[X] = fk.apply(af) - def productK[F[_], G[_]](af: F[X], ag: G[X]): Tuple2K[F, G, X] = ??? \ No newline at end of file + def productK[F[_], G[_]](af: F[X], ag: G[X]): Tuple2K[F, G, X] = Tuple2K(af, ag) \ No newline at end of file