Hello Scala Community!

I’d like to open the discussion for the pending SIP on dropping existential types from the language. You can read a full writeup on the details here.

Summary:

Existential types that can be expressed using only wildcards (but not forSome ) are still supported, but are treated as refined types.

Please read the link above for full details.

Implications

I’m aware of two issues (both from my time on SBT). Both of these issues arise from limitations in type inference and using existentials to be able to drop explicit type annotations in two scenarios:

Scenario 1: Higher kinded types

SBT relies on forSome for code like the following:

def joinAny[M[_]](inits: Seq[Initialize[M[T]] forSome { type T }]): Initialize[Seq[M[_]]]

Where “Initialize” is effectively an Applicative functor / Reader-style monad. In the past, existentials were the only way to get Scala’s type inference to handle these styles of methods.

Scenario 2: F-Bounded polymorphism/quantification

SBT has the following:

type Key = K forSome { type K <: Scoped.ScopingSetting[K] with Scoped }

This, again, was used to simplify defining these types and ensuring type inference preserved what was needed in the API.

I believe BOTH of these use cases (not explicitly outlined in the proposal) should be resolved with better type inference generally available in DOTTY. (I have not yet confirmed, but will get back to this thread once I have time too).

Opening this up for general community discussion and insight into any other use cases that would not be covered with wildcards or dependent types.