Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Kind Inference #123

Open
neko-kai opened this issue May 30, 2020 · 0 comments
Open

Kind Inference #123

neko-kai opened this issue May 30, 2020 · 0 comments

Comments

@neko-kai
Copy link

Allow kind and variance of type parameters to be inferred based on usage in the type signature or inside the template body instead of having to always be specified fully.

Example:

trait Monad[F[+_]]
trait Traverse[CC[+_]]

// infer the kind [_] for F based on usage in template
trait Credential[+F, -A] { 
  def (a: A).check: F[Boolean]
}

// infer the kind [_] and variance + for F & CC based on usage in signature
def checkAllCredentials[F: Monad, CC: Traverse, A: Credential[F, *]](
  credentials: CC[A]
): F[Boolean] =
  credentials.traverse(_.check).map(_.forall(identity))

Motivation:

There's a major syntactic penalty attached both to adding type parameters and to using any variance in type parameters except invariance. e.g. to specify a bifunctor-like data type one has to add and additional of 7 symbols to the type parameter: [+_, +_], for a ZIO-like bifunctor+profunctor type it's 11 symbols - [-_, +_, +_]. This affects libraries that abstract over such types, e.g. BIO typeclass hierarchy.

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

No branches or pull requests

1 participant