kailuowang / mainecoon Goto Github PK
View Code? Open in Web Editor NEWTransform and compose tagless final encoded algebras in scala
License: Apache License 2.0
Transform and compose tagless final encoded algebras in scala
License: Apache License 2.0
Hi there,
Just stumbled onto this project. It looks like you and I independently ended up in pretty much the same space. If you haven't yet, take a look at diesel.
Maybe we can work together?
Lloyd
I'd love to see a very simple ApplyK
typeclass that'd let us use something like this:
def map2K[F[_], G[_], H[_]](af: A[F], ag: A[G])(f: Tuple2K[F, G, ?] ~> H): A[H]
And it should also be able to be derived fairly easily, right?
There is a relatively popular linter for Scala - wartremover. It works as a compiler plugin, which allows it to tap into typing and other low-level compiler details to provide some pretty useful checks ("warts"). The problem is that it has to work after macro expansion phase. As far as I understand, there is no reliable way to detect expanded macros, though.
This means that mainecoon's generated code gets checked as well. In particular, this sample:
@autoFunctorK
trait Foo[F[_]] {
def pure[A](a: A): F[A]
}
triggers this warning:
<macro>:9: [wartremover:ImplicitParameter] Implicit parameters are disabled
object autoDerive { implicit def fromFunctorK[F[_], G[_]](implicit fk: _root_.cats.~>[F, G], FK: _root_.mainecoon.FunctorK[({ type λ[Ƒ[_]] = Foo[Ƒ] })#λ], af: Foo[F]): Foo[G] = FK.mapK(af)(fk) }
^
The root of the issue here seems to be implicit parameter FK
, which includes neither F
, nor G
.
Here are the ways for a user to get rid of this warning:
autoFunctorK
@SuppressWarnings
annotation to the companion objectThe third approach, though a bit counterintuitive, allows at least some granularity.
It would be far better to only exclude the generated code. This, however, can only be done in mainecoon itself. This would only require adding this annotation to generated definitions:
@SuppressWarnings(Array("org.wartremover.warts.ImplicitParameter"))
When we have a MonadTrans
type class we can add a embed
method to FunctorK
:
def embed[M[_], MT[_[_], _]](fa: F[M])(implicit D: MonadTrans[MT], M: Monad[M]): F[MT[M, ?]] = functorK.mapK(fa)(new (M ~> MT[M, ?]) {
override def apply[A](fa: M[A]): MT[M, A] = D.lift(fa)
})
Maybe it would be nice if we can define the natural transformation implicitly such that we can embed a M[_]
into a complex monad transformer stack. Like Future ~> EitherT[WriterT[Future, List[String], ?], String, ?]
.
(Interpreter[F], Interpreter[G]) => Interpreter[λ[A => (F[A], G[A])]]
example use case at https://github.com/edmundnoble/Neil/blob/master/src/main/scala/io/enoble/svg2d/Main.scala#L120
To be consistent with the Cats version :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.