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. Query regarding an unusually behaving code (Abhishek Kumar) 2. Re: Query regarding an unusually behaving code (Grzegorz Milka) 3. Re: Query regarding an unusually behaving code (akash g) ---------------------------------------------------------------------- Message: 1 Date: Fri, 13 Nov 2015 12:06:42 +0530 From: Abhishek Kumar <abhishekkm...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <Beginners@haskell.org> Subject: [Haskell-beginners] Query regarding an unusually behaving code Message-ID: <caeagxqwux+bwnxsf+uggnlezbz9+w4njfv1l9ch8qzqcqdu...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Bellow is my code for returning a list of digits given an integer.I'm unable to find any bug in it but somehow it crashes any computer I run it on when I try to calculate digs 100.Please tell me bug in my code. let digs 0 =[0] let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] digs 100 Thanks Abhishek -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151113/1db891a7/attachment-0001.html> ------------------------------ Message: 2 Date: Fri, 13 Nov 2015 07:43:52 +0100 From: Grzegorz Milka <grzegorzmi...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Query regarding an unusually behaving code Message-ID: <564586a8.7090...@gmail.com> Content-Type: text/plain; charset="windows-1252" The problem is that you define digs twice and the second definition overshadows the first one. This makes your recursion infinite. You should define all cases at once like: let digs 0 = [0]; digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] Greg On 13.11.2015 07:36, Abhishek Kumar wrote: > Bellow is my code for returning a list of digits given an integer.I'm > unable to find any bug in it but somehow it crashes any computer I run it > on when I try to calculate digs 100.Please tell me bug in my code. > > let digs 0 =[0] > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > digs 100 > > Thanks > Abhishek > > > > _______________________________________________ > 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/20151113/48f19443/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151113/48f19443/attachment-0001.sig> ------------------------------ Message: 3 Date: Fri, 13 Nov 2015 12:17:33 +0530 From: akash g <akabe...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Query regarding an unusually behaving code Message-ID: <caliga_dl-edrq9wtwlsvfqz29xkckqsgyex7v8ytxtb3w9g...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" This is because the second let redefines your first definition. Hence, you don't have a base case anymore. digs 0 =[] digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] When I compile this with ghc though, it works fine. This is how ghci works, I'd presume. On Fri, Nov 13, 2015 at 12:06 PM, Abhishek Kumar <abhishekkm...@gmail.com> wrote: > Bellow is my code for returning a list of digits given an integer.I'm > unable to find any bug in it but somehow it crashes any computer I run it > on when I try to calculate digs 100.Please tell me bug in my code. > > let digs 0 =[0] > let digs x = (digs (x `div` 10)) ++ [(x `rem` 10)] > digs 100 > > Thanks > Abhishek > > _______________________________________________ > 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/20151113/6e961e8e/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 89, Issue 23 *****************************************