[Haskell-beginners] Query regarding an unusually behaving code

Grzegorz Milka grzegorzmilka at gmail.com
Fri Nov 13 06:43:52 UTC 2015


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 at 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.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.sig>


More information about the Beginners mailing list