[Haskell-beginners] Non-exhaustive patterns

Pietro Grandinetti pietro.gra at hotmail.it
Sun Dec 12 05:21:34 UTC 2021


Hello - I think the pattern for the empty list (as second argument) is missing.
________________________________
From: Beginners <beginners-bounces at haskell.org> on behalf of Galaxy Being <borgauf at gmail.com>
Sent: Sunday, December 12, 2021 6:14:03 AM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners at haskell.org>
Subject: [Haskell-beginners] Non-exhaustive patterns

This code

myTakePM :: Int -> [a] -> [a]
myTakePM 0 _ = []
myTakePM n (x:xs) = x : myTakePM (n-1) xs

is bad because it allows

myTakePM 4 [1,2,3]
 [1,2,3*** Exception: <interactive>:(395,1)-(396,41): Non-exhaustive patterns in function myTakePM

I knew it would not work, but why is it calling this essentially a partial function? How does it know this? Again, I expected an error, but what is this Non-exhaustive patterns in function myTakePM saying? Or, said another way, what exactly is non-exhaustive about this?
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borgauf at gmail.com<mailto:borgauf at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20211212/b25e8d88/attachment.html>


More information about the Beginners mailing list