Pattern Matching on Literals
Learn about pattern matching on literal values.
We'll cover the following...
Pattern matching on literals
Instead of using pattern variables, we can also write function equations using literal values as patterns. Here is an example:
isZero :: Int -> Bool
isZero 0 = True
isZero n = False
This function has two defining equations. The first one uses the numeric literal 0
as the pattern. We can read it as "if the argument to isZero
is 0
, the result is True
". The second equation uses a ...