[Haskell-cafe] Tail recursive
J.W. Krol
jkrzzz at live.com
Wed Dec 19 17:17:19 CET 2012
From: jkrzzz at live.com
To: haskell-cafe at haskell.org
Subject: Tail recursive
Date: Wed, 19 Dec 2012 17:07:14 +0100
Hello,
I need a non tail recursive version of scanl, to produce a large enough list of >100K vectors (vectors defined as a list)
I have following code:
scanl'::(a -> a -> a) -> a -> [a] -> [a]scanl' f q ls = scanl'' ls (q:[]) where scanl'' (x:xs) ys = let h = head ys x' = f x h ys' = x':ys in h `seq` x' `seq` ys' `seq` scanl'' xs ys' scanl'' [] ys = ys
If I call this function as below I still got stack-overflow error:
head (scanl' (zipWith (+)) ([0,0]) (take 100000 (repeat [0,1])))
What do I wrong. I am not an experienced Haskell programmer, but find the behavior quite unexplainable.
Thank for your answer.
RegardsJacq
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121219/72f1bcb6/attachment.htm>
More information about the Haskell-Cafe
mailing list