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

Support deriving typeclasses with an effectful return type #43

Closed
Fristi opened this issue Nov 21, 2017 · 5 comments
Closed

Support deriving typeclasses with an effectful return type #43

Fristi opened this issue Nov 21, 2017 · 5 comments
Assignees

Comments

@Fristi
Copy link

Fristi commented Nov 21, 2017

Like a Decoder[A] returning a Either[String, A], for each member of a type class we need to decode it. Currently construct is deficient to do that.

Current

def construct[Return](makeParam: Param[Typeclass, Type] => Return): Type

How should this look like for effects?

def construct[Effect[_] : Applicative, Return](makeParam: Param[Typeclass, Type] => Effect[Return]): Type

Yet this would imply that for type classes with multiple methods the effect type will be the same (like codecs, in scodec this holds though)

Where do we get Applicative from? I wouldn't favor depending on cats or scalaz

@propensive
Copy link
Collaborator

propensive commented Nov 21, 2017

I don't think the API needs to be this specific, does it? Could you work with a new construct method which takes a Seq[Any] of the parameters? i.e.

def construct(paramValues: Seq[Any]): Type

You could then fold the ctx.parameters however you like, to get the effect and then pass the Seq[Any] of the parameters to the new construct.

@propensive
Copy link
Collaborator

We would, of course, lose some typesafety with this version. The sequence is no longer length-safe, and it would be possible to treat the parameters non-uniformly. I would like to keep the old construct method around, maybe under a different name.

@propensive propensive self-assigned this Nov 22, 2017
@propensive propensive changed the title Deriving type classes which have a effectful return type Support deriving typeclasses with an effectful return type Nov 22, 2017
@sirthias
Copy link
Contributor

+1 for adding something like

def construct(paramValues: Seq[Any]): Type

I'm currently trying to write a "conserving tree rewriter" typeclass that is supposed to return the original case class instance if all its members have been rewritten to the identical instance.
With this new construct overload this would be easy. The current design makes this quite hard.

@fommil
Copy link
Contributor

fommil commented Aug 3, 2018

oh, I just fixed this in #120 for Either... but doing it in the general case for flatMap would be good.

@Fristi
Copy link
Author

Fristi commented Jan 2, 2019

I think this is already done right?

@Fristi Fristi closed this as completed Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants