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 user-defined lifted types #46

Closed
propensive opened this issue Nov 22, 2017 · 1 comment
Closed

Support user-defined lifted types #46

propensive opened this issue Nov 22, 2017 · 1 comment
Assignees

Comments

@propensive
Copy link
Owner

@propensive propensive commented Nov 22, 2017

This feature has several advantages over v0.6.1:

  1. Magnolia would no longer need to be a runtime dependency of any libraries which use it,
  2. implicit evidence (of some type other than the typeclass being derived) could be requested for each parameter,
  3. runtime and compile-time performance could be improved by reducing garbage generation

The macro currently instantiates CaseClass, SealedTrait, Subtype and Param instances which it passes to the user-defined method, combine. Magnolia provides fully-functional versions of these types. That is, including all the features which may be utilized in any given derivation, regardless of whether they are actually used or not.

However, there is scope for alternative implementations of these types to be used, and it should be possible for users to abstract over the instantiation of these types in general ways, for example by resolve additional typeclass instances on the type of the parameter (which is not currently possible from within the combine method definition, as the parameter type is existential by that point).

I propose to give users the option of providing their own implementations of these types, to be instantiated by new methods provided on the derivation object, namely,

  • param,
  • caseClass,
  • sealedTrait, and
  • subtype

As with combine and dispatch, the signatures of these methods would not have to adhere to a fixed interface (in the object-oriented sense), and could take additional type parameters or implicit parameters, but would be invoked by the macro which would inspect their parameters' names, and supply values only to those parameters in the signature. Any parameters (e.g. support for default values) not listed as the parameter would not be generated.

The first advantage would be that a number of ephemeral objects which exist only for covariant or only for contravariant typeclasses would not need to be instantiated for all cases, even when they are not used in the derivation. This should be beneficial for both compile time and runtime performance.

The second advantage would be that user-defined classes could be used in preference to Magnolia's default implementations, thereby obviating the need for Magnolia to be a runtime dependency. Given the library is likely to be useful for a number of other projects, the risk of a diamond dependency problem could be eliminated, while for application (i.e. non-library) developers, the tersity of the status quo would apply.

The existing API would remain unchanged if users did not provide any of the custom methods.

@propensive propensive self-assigned this Nov 22, 2017
@propensive propensive changed the title Support user-defined parameter types Support user-defined lifted types Nov 23, 2017
@SystemFw
Copy link

@SystemFw SystemFw commented Nov 23, 2017

Nice to see this being worked on :)

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

Successfully merging a pull request may close this issue.

None yet
2 participants