-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip?] scalaz compiler plugin to guarantee sufficient typeclass definitions #1861
Conversation
trait DeriveMap[F[_]] extends ApplicativeClass[F] with MonadClass.Alt[DeriveMap[F]] { | ||
final override def map[A, B](ma: F[A])(f: (A) => B): F[B] = ap(ma)(pure(f)) | ||
} | ||
override def map[A, B](ma: F[A])(f: A => B): F[B] = ap(ma)(pure(f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Epic.
trait DerivePmap[F[_]] extends PhantomClass[F] with Alt[DerivePmap[F]] { | ||
final override def pmap[A, B](ma: F[A]): F[B] = contramap(map(ma)(_ => ()))(_ => ()) | ||
} | ||
def pmap[A, B](ma: F[A]): F[B] = contramap(map(ma)(_ => ()))(_ => ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -17,18 +17,18 @@ trait FiberInstances { | |||
|
|||
implicit def fiberApplicative[E]: Applicative[Fiber[E, ?]] = | |||
instanceOf(new ApplicativeClass[Fiber[E, ?]] { | |||
final def pure[A](a: A): Fiber[E, A] = new Fiber[E, A] { | |||
override def pure[A](a: A): Fiber[E, A] = new Fiber[E, A] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final override def
?
@@ -9,73 +11,32 @@ package types | |||
* https://typelevel.org/blog/2014/03/09/liskov_lifting.html | |||
*/ | |||
trait IsCovariantClass[F[_]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no @minimal
?
@@ -9,63 +11,32 @@ package types | |||
* https://typelevel.org/blog/2014/03/09/liskov_lifting.html | |||
*/ | |||
trait IsContravariantClass[F[_]] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minimal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is quite nice indeed.
What I liked about previous approach is that it forced users to be conscious of what methods are derived, and with which implementation (ie. all methods are either final or abstract).
But the getting ride of the boilerplate is nice and probably worth it.
} | ||
|
||
trait Alt[D <: Alt[D]] | ||
def flatMap[A, B](ma: M[A])(f: A => M[B]): M[B] = flatten(map(ma)(f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this cause an issue with default impl of map
in Monad
? ie if one override only flatten
then we can have a circular definition between map
and flatMap
:
def flatMap[A, B](ma: M[A])(f: A => M[B]): M[B] = flatten(map(ma)(f))
def map[A, B](ma: M[A])(f: A => B): M[B] = flatMap(ma)(a => pure(f(a)))
this case was checked by the "Alt
"-encoding, would be nice to preserve this check.
I think there is some other similar cases as well.
No description provided.