Ordered variants in Haskell let you do things like
funky (x:y:xs) = ... -- I'm guaranteed to have two elements or more
funky (x:xs) = ... {- This pattern would have matched a long list, b
+ut since
the previous variant came first, we know the l
+ist is
of length 1 or 2. *
-}
This is incredibly useful sometimes. Okay, when I want when I know where to find it. :-)
* For folks not familiar with Haskell who count three or two items in the two patterns and don't see why I'm talking of lists of at least two and one or two elements respectively: in Haskell, "(a:b)" means a is an element and b is a list of zero or more elements. That's why by convention you see names like "xs" and "ys", pronounced "exes" and "whys", though there's nothing in the language to enforce names like that. The expression (x:y:xs) means (x:(y:xs)). |