Change Either subclasses type parameters?


I think we need a SIP for changes on core classes like this, not only a PR.


The current design is inconsistent:

  • None has zero type parameter, while its super type Option has one.
  • Left and Right have the same type parameters as their super type Either.
  • Failure has the same type parameter as their super type Try.

I thought the consistency is the strongest reason for this change.

Note that this change could be almost source compatible with the help of opaque types.

package util {
  enum Either[+L, +R] {
    case Left(l: L) extends Either[L, Nothing]
    case Right(r: R) extends Either[Nothing, R]

package object util {

  trait OpaqueTypes {
    type Left[+L, +R] <: Either.Left[L]
  val opaqueTypes: OpaqueTypes = new OpaqueTypes {
    type Left[+L, +R] = Either.Left[L]
  type Left[+L, +R] = opaqueTypes.Left[+L, +R] 
  object Left {
    def apply ...
    def unapply ...


Don’t take my word for it, but I’m not so sure.

Also a good PR helps a SIP anyways so there’s reason to do one nonetheless, IMO.


The collections redesign didn’t go through the SIP process, so …


What do people think of this open PR for Either?
it will allow writing things like Either.left[Int]("empty") and that would be typed as Either[String, Int]