arrow-meta icon indicating copy to clipboard operation
arrow-meta copied to clipboard

Type Class Discovery & Resolution

Open raulraja opened this issue 6 years ago • 1 comments

With compiler plugins is very likely we can implement full-blown type classes including resolution and automatic derivation.

Type class derivation

  • By default look first for user declared extensions following the KEEP-87 candidate resolution.
  • (User) Denote type class instances as derivable by annotating the annotation method flagged as @derivable. For example in Functor<F> @derivable Kind<F, A>.map...`.
  • Intercept declaration and class building phase to scan all interface which contains a single type argument. These are the type class candidates.
  • Intercept declaration and class building phase of all types in search for compatible matches that can be used to implement the @derivable method if it exists. If the type class contains no derivable method we stop otherwise we try to find a compatible match. In this step we also want to skip types that already include instances for this type class following the KEEP 87 resolution rules.
  • When a matching type is found for a derivable method we can create automatically a type class instance for it and enrich the data type companion with the typeclass instances as a property.
  • This can potentially be done in the ClassBuilderInterceptorExtension phase.

Call site resolution

  • For all expressions that make a call into a type class constrained function look for instances that may be injected with the same resolution rules at KEEP-87

This feature should be part or is closely related with arrow-kt/arrow#1638

raulraja avatar Jun 05 '19 09:06 raulraja

Currently being implemented with Type Proofs

raulraja avatar Dec 11 '19 11:12 raulraja