Skip to content

Split TupledFunction into "read" and "write" type classes #17641

@neko-kai

Description

@neko-kai

Currently TupledFunction is limited as a solution for abstraction over fucntion arity - it can only abstract over arity of vanilla function types, it cannot turn inheritors of Function*, singleton function objects or refined function types into functions of tuples. It's also forcefully invariant and unwieldy when variance is involved.

Both of these can be solved by splitting TupledFunction into two type classes, one for converting into tupled function and one for converting from a tupled function. That way the "read" type class instance can still be synthesized for types that can never be created from a tupled function - such as singleton function objects. Both read and write type classes can also be made variant.

sealed trait ToTupledFunction[-F, +G]:
  def tupled(f: F): G

sealed trait FromTupledFunction[-G, +F]:
  def untupled(g: G): F

sealed trait TupledFunction[F, G] extends ToTupledFunction[F, G] with FromTupledFunction[G, F]:
  def tupled(f: F): G
  def untupled(g: G): F

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions