Another example of a nice use of pattern matching I came upon while practicing basic hs- pattern match over a tuple of two booleans that you're creating ad hoc. This is great because it avoids the nesting of ifs/ternaries and is more clear what's going on.
getClassification :: Int -> Int -> Classification
getClassification target aliquotSum =
case (target > aliquotSum, target < aliquotSum) of
(True, _) -> Deficient
(_, True) -> Abundant
_ -> Perfect
In javascript we might write it thusly:
const getClassification = (target, aliquotSum) =>
return target > 'aliquotSum'
? 'Deficient'
: target < aliuotSum
? 'Abundant'
: 'Perfect'
or in python:
def getClassification(target, aliquotSum):
if (target > aliquotSum):
return 'Deficient'
if (target < aliquotSum):
return 'Abundant'
return 'Perfect'
first example here