Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Non-exhaustive patterns (Galaxy Being) 2. Re: Non-exhaustive patterns (Pietro Grandinetti) 3. But I just want a function that returns stack depth! (Michael Turner) 4. Re: But I just want a function that returns stack depth! (יהושע ולך) ---------------------------------------------------------------------- Message: 1 Date: Sat, 11 Dec 2021 23:14:03 -0600 From: Galaxy Being <borg...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Non-exhaustive patterns Message-ID: <cafahfsxzdqvh3fovvbjozxyso6pysjdeh1p9fod2pmz5mdu...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" 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 borg...@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20211211/f79ec1b2/attachment-0001.html> ------------------------------ Message: 2 Date: Sun, 12 Dec 2021 05:21:34 +0000 From: Pietro Grandinetti <pietro....@hotmail.it> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Non-exhaustive patterns Message-ID: <pr2pr09mb3003c1974298e1fb4b6404e8fc...@pr2pr09mb3003.eurprd09.prod.outlook.com> Content-Type: text/plain; charset="utf-8" Hello - I think the pattern for the empty list (as second argument) is missing. ________________________________ From: Beginners <beginners-boun...@haskell.org> on behalf of Galaxy Being <borg...@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@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 borg...@gmail.com<mailto:borg...@gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20211212/b25e8d88/attachment-0001.html> ------------------------------ Message: 3 Date: Sun, 12 Dec 2021 19:57:03 +0900 From: Michael Turner <michael.eugene.tur...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] But I just want a function that returns stack depth! Message-ID: <canhebiiigcbhu9wbcqtjwypnw9btesnzsxfbp_+rmewdmhs...@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" The following prints 1, as you'd expect: ----------------- import GHC.Stack foo :: HasCallStack => IO () foo = do print (length (getCallStack callStack)) main = foo ------------------- But when I make it this: ... l <- getCallStack callStack ; print (length l) I get all this: ------------------------------------------ ... • Couldn't match type ‘[]’ with ‘IO’ Expected type: IO ([Char], SrcLoc) Actual type: [([Char], SrcLoc)] • In a stmt of a 'do' block: l <- getCallStack callStack In the expression: do l <- getCallStack callStack print (length l) In an equation for ‘foo’: foo = do l <- getCallStack callStack print (length l) | 5 | l <- getCallStack callStack ; | ^^^^^^^^^^^^^^^^^^^^^^ -------------------------------------------- What am I not seeing? Regards, Michael Turner Executive Director Project Persephone 1-25-33 Takadanobaba Shinjuku-ku Tokyo 169-0075 Mobile: +81 (90) 5203-8682 tur...@projectpersephone.org Understand - http://www.projectpersephone.org/ Join - http://www.facebook.com/groups/ProjectPersephone/ Donate - http://www.patreon.com/ProjectPersephone Volunteer - https://github.com/ProjectPersephone "Love does not consist in gazing at each other, but in looking outward together in the same direction." -- Antoine de Saint-Exupéry ------------------------------ Message: 4 Date: Sun, 12 Dec 2021 13:46:28 +0200 From: יהושע ולך <yehoshu...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] But I just want a function that returns stack depth! Message-ID: <CAMcanRWt9_qJk5C=3y1z5pbfx7gjngmfta4u18smfcj75g0...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" have another look at https://hackage.haskell.org/packaggetCallStackgetCallStacke/base-4.16.0.0/docs/GHC-Stack.html#v:callStack <https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-Stack.html#v:callStack> You need ``` let l = getCallStack callStack print (length l) ``` the `getCallStack` does not return an "IO" value.. On Sun, Dec 12, 2021, 12:58 Michael Turner <michael.eugene.tur...@gmail.com> wrote: > The following prints 1, as you'd expect: > ----------------- > import GHC.Stack > > foo :: HasCallStack => IO () > foo = do > print (length (getCallStack callStack)) > > main = > foo > ------------------- > But when I make it this: > ... > l <- getCallStack callStack ; > print (length l) > > I get all this: > ------------------------------------------ > ... > • Couldn't match type ‘[]’ with ‘IO’ > Expected type: IO ([Char], SrcLoc) > Actual type: [([Char], SrcLoc)] > • In a stmt of a 'do' block: l <- getCallStack callStack > In the expression: > do l <- getCallStack callStack > print (length l) > In an equation for ‘foo’: > foo > = do l <- getCallStack callStack > print (length l) > | > 5 | l <- getCallStack callStack ; > | ^^^^^^^^^^^^^^^^^^^^^^ > -------------------------------------------- > > What am I not seeing? > > > Regards, > Michael Turner > Executive Director > Project Persephone > 1-25-33 Takadanobaba > > Shinjuku-ku Tokyo 169-0075 > Mobile: +81 (90) 5203-8682 > tur...@projectpersephone.org > > Understand - http://www.projectpersephone.org/ > Join - http://www.facebook.com/groups/ProjectPersephone/ > Donate - http://www.patreon.com/ProjectPersephone > Volunteer - https://github.com/ProjectPersephone > > "Love does not consist in gazing at each other, but in looking outward > together in the same direction." -- Antoine de Saint-Exupéry > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20211212/973ea3a2/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 161, Issue 1 *****************************************