Literal patternΒΆ
A literal pattern consists of a single specific value. For example,
f(5) = "hi"
uses 5
as a literal pattern, and means that on the specific input
5
, the function f
should output "hi"
.
Literal patterns can be used with
- The unit value, e.g.
f(unit) = ...
- Booleans, e.g.
f(true) = ...
- Natural numbers, e.g.
f(5) = ...
- Integers, e.g.
f(-5) = ...
- Rational numbers, e.g.
f(1/2) = ...
- Characters, e.g.
f('x') = ...
- Strings, e.g.
f("hello") = ...
Note that f(-5) = ...
and f(1/2) = ...
are technically
arithmetic patterns rather than true literal
patterns, but the distinction does not matter very much.