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 polymorphic tagged unions #196

Open
tpetrucciani opened this issue Mar 13, 2020 · 0 comments
Open

Support polymorphic tagged unions #196

tpetrucciani opened this issue Mar 13, 2020 · 0 comments
Labels

Comments

@tpetrucciani
Copy link
Contributor

The support for tagged unions introduced by #39 is limited to monomorphic tagged unions. It would be nice to support those with type parameters too.

As an example use case, in an internal project we have a polymorphic Subset type used to describe whitelists or blacklists:

sealed trait Subset[T] {
  def selection: Set[T]
  def mode: SubsetMode
}

case class Whitelist[T](
  selection: Set[T]
) extends Subset[T] {
  val mode = SubsetMode.Whitelist
}

case class Blacklist[T](
  selection: Set[T]
) extends Subset[T] {
  val mode = SubsetMode.Blacklist
}

To have it work with metarpheus, we need to use instead a "flattened" representation as a product type. While the two are isomorphic, the tagged union representation is arguably safer because it encourages checking the mode before checking the selection, so it would be good to support it.

(Standard generic tagged union types like Option are already supported as special cases, as they were before #39.)

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

No branches or pull requests

1 participant