Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

hrhino
Copy link
Member

@hrhino hrhino commented Jun 6, 2018

No description provided.

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))
Copy link
Contributor

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)(_ => ()))(_ => ())
Copy link
Contributor

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] {
Copy link
Contributor

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[_]] {
Copy link
Contributor

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[_]] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minimal

Copy link
Member

@jbgi jbgi left a 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))
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants