I try to keep an eye out for quick wins that can improve my Haskell code. One thing that annoys me in the code I have written before is the use of pattern matching at the top level where the function name is repeated for each pattern.
Greet, greet, greet, greet… Sigh. Would you agree that the repetition becomes a bit tedious? Let’s put those patterns into a case expression instead.
Much better! Notice also how the parenthesis around the Maybe pattern can be removed.
If you want you can take this even further using the LambdaCase language extension. Either use the flag
-XLambdaCase when compiling or add a language pragma at the top of your module as in the following example.
If you want to find out more about syntax extensions you should check out the GHC users guide. Thanks for reading. Happy pattern matching!