2 ms·
I can think of plenty cases where I would want to limit the input space of a function to a known set of literals. Just as an example; the `document.getContext`
by esarbe 5y ago
I can think of plenty cases where I would want to limit the input space of a function to a known set of literals.
Just as an example; the `document.getContext` [0] api takes a string argument to select the context canvas.
Without literal types, you cannot enforce this to a set of valid values. Literal types gives you the power to tell the compiler, which values are valid.
Since there are other programming languages that support literal types, it's not just Scala sophistry. :-P
[0] https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasE...