Last Updated: June 19, 2019
·
158
· maldad

Always look for patterns

One of the things that I always try to remember when I'm resolving a problem in Haskell is: Lazyness.
Take this code for example:

module Alarm where

setAlarm :: Bool -> Bool -> Bool
setAlarm True False = True
setAlarm False False = False
setAlarm False True = False
setAlarm True True = False

You can clearly note a pattern where the second argument doesn't matter, so use wildcards in these scenarios:

setAlarm :: Bool -> Bool -> Bool
setAlarm True False = True
setAlarm _ _ = False