4 ms·
> The idea of needing a 1-5 compile-time constrained value is rare in any application I have worked with, because either you'd use an enum, or the "5" isn't rea
by runeks 6y ago
> The idea of needing a 1-5 compile-time constrained value is rare in any application I have worked with, because either you'd use an enum, or the "5" isn't really known at compile time.
The OneToFive-type is used to illustrate a point, not because it’s practically useful.
> A non-negative floating point number would be a common one I think, e.g. for a coordinate. I've not been keeping up with Haskell but can you guarantee this at compile time?
No. It’s not possible.
But, as you point out, this is not a problem since values like these are rarely known at compile-time.
And, more importantly, if you can’t trust a programmer to write the correct constant, how can you trust the same programmer to write the correct type for this constant (“non-negative float”)?
Except by using a quasi-quoter (which amounts to parsing a string into a float at compile-time)