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

Type classes: expose super class functions in sub classes. (WIP) #1623

Closed
wants to merge 1 commit into from

Conversation

jbgi
Copy link
Member

@jbgi jbgi commented Jan 21, 2018

This is an alternative approach to #1620 achieving the goal of ensuring inheritance-based implementations of type classes, here via seal of type class + Template.

This PR also expose super class functions in sub classes: this avoid going through no-op methods to switch to super classes in many cases.

WIP: Monoid/Semigroup and Functor->Monad only. For early review. Remaining type classes will follow.

 Also ensure inheritance-based implementations via seal of type class.
 This avoid going through no-op invoke virtuals in most cases.

 WIP: Monoid/Semigroup/Functor->Monad only.
@jdegoes
Copy link
Member

jdegoes commented Jan 23, 2018

@jbgi Looks good to me! /cc @edmundnoble

@TomasMikula
Copy link
Member

👍 I like it. It even seems clearer to me than the previous approach.

@TomasMikula
Copy link
Member

Something for future thought: Maybe we could save some Templates if we defined the actual typeclasses to be used as

type Monad[F[_]] = InstanceOf[Monad.Class[F]]

where InstanceOf would declared as

type InstanceOf[A] <: A

and (privately) implemented as

type InstanceOf[A] = A

Now implementations of Monad wouldn't have to also extend Bind, Applicative, Apply, Functor. They would just extend Monad.Class and be "tagged" as Monad by zero-cost wrapping in InstanceOf.

(Implicits for Monad, if any, would now have to go in the companion of Monad.Class.)

@jbgi
Copy link
Member Author

jbgi commented Jan 23, 2018

Interesting, need to try!

@TomasMikula
Copy link
Member

Travis says that some tuts need to be fixed.

@jbgi
Copy link
Member Author

jbgi commented Feb 6, 2018

@TomasMikula quick update: I tested your suggested encoding this week-end. Works very well and avoid quite a bit of boilerplate classes. Currently preparing a replacement for this PR use it. (also I am thinking that we could also use it in 7.3.x ...)

@TomasMikula
Copy link
Member

Good to hear! Though I think it's fine to finish this PR (by fixing the build) and do the refactoring in the next round.

@jbgi
Copy link
Member Author

jbgi commented Feb 8, 2018

closing in favor of #1647.

@jbgi jbgi closed this Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants