SIP 18 (https://docs.google.com/document/d/1nlkvpoIRkx7at1qJEZafJwthZ3GeIklTFhqmXMvTX9Q/edit) introduced language imports, and gating higher kinds behind the import
language.higherKinds was part of that SIP.
The rationale at the time was
Why control it? Higher kinded types in Scala lead to a Turing-complete type system, where compiler termination is no longer guaranteed. They tend to be useful mostly for type-level computation and for a relatively narrow set of highly generic design patterns. The level of abstraction implied by these design patterns is often a barrier to understanding for newcomers to a Scala codebase. Some syntactic aspects of higher-kinded types are hard to understand for the uninitiated and type inference is less effective for them than for normal types. Because we are not completely happy with them yet, it is possible that some aspects of higher-kinded types will change in future versions of Scala. See my post “Scala - A Roadmap” to scala-language for details. So an explicit enabling also serves as a warning that code involving higher-kinded types might have to be revised in the future.
This reasoning is still preserved in the doc comment.
I’d like to discuss whether the rationale presented is still applicable, whether there are other reasons to have the feature behind a flag, and if higher kinds could be enabled without a flag.
Pulling the reasons apart, we have
- Compiler termination is not guaranteed
- The applicability is relatively narrow
- Using HKTs is a barrier of entry to newcomers in a code base
- Type inference is less effective
- It is possible that details may change in the future
With cats-effect and fs2 quickly gaining traction, HKTs are quickly becoming more common in my own scala projects. This makes the second point weaker.
While I agree using HKTs is a barrier of entry to newcomers in a code base, I suspect this warning is rarely heeded. It doesn’t seem to me that many code bases choice to (not) use HKTs is triggered by the warning on this import, and I don’t think this warning helps with that.
-Ypartial-unification eliminates important issues with inference, and https://github.com/scala/scala/pull/6309 while not yet merged seems to be a (wonderful) formality at this point.
As far as I know, the final comment about changing HKT semantics in the (indeterminite) future isn’t applicable anymore.
All in all, I believe it’s rare that people accidentally use HKTs, and possibly even rarer that this warning saves someones programmatic bacon. With the evolution of scala itself and the scala ecosystem, I don’t think it’s needed anymore. Is it maybe time to enable HKTs by default?