Allow for Compile-Time Checked Intervals for Parameters Expecting Literal Values

I think what you're pitching is a much reduced form of Dependent Types. This is also a feature I would love to see in swift and find myself reaching for all the time.

There has been some previous discussion on the topic, see:

Syntactically I think it would make more sense to write the value constraints using existing notation. Something like this comes to mind:

typealias Height = Int where self > 0, self <= 10

This is also related to previous discussion on newtype functionality, see here.

3 Likes