...

/

Pattern Matching on Literals

Pattern Matching on Literals

Learn about pattern matching on literal values.

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 ...