[Haskell-cafe] Another Question

Ketil Malde ketil at malde.org
Thu Feb 3 09:28:03 CET 2011


Navin Rustagi <navin_kunta at yahoo.com> writes:

> It gives the error ERROR - Control stack overflow. I assume it is
> because of the lazy evaluation. 

Yes, you're just building a tower of additions, and when evaluating
this, you blow up the stack.  You need to make sure to evaluate the
tuple element each time, so instead of 

>    case ys of  'A'  -> (elf, els+1,elr,ell,elx) 

write:

>    case ys of  'A'  -> els `seq` (elf, els+1,elr,ell,elx)

(Strictly speaking this will only evaluate the previous value, but your
 tower of additions will now have maximum one floor)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants



More information about the Haskell-Cafe mailing list