[Haskell-beginners] Regarding defining cases exhaustively

Lai Boon Hui laiboonh at gmail.com
Mon Oct 10 05:15:17 UTC 2016


Hi all,

I have this code

myMaximumBy :: (a -> a -> Ordering) -> [a] -> a
myMaximumBy _ [] = undefined
myMaximumBy _ (x:[]) = x
myMaximumBy f (x:xs) =
  case f x maxRestOfList of
    GT -> x
    _ -> maxRestOfList
    where maxRestOfList = myMaximumBy f xs

whereby the case myMaximumBy _ [] will never happen because case
myMaximumBy _ (x:[]) = x prevents that from happening. However i will still
like to define it to keep -Wall warning from complaining.

Is using undefined acceptable or is there a better way?

-- 
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161010/d46a3ed1/attachment.html>


More information about the Beginners mailing list