Open
Description
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.)