From: jkr...@live.com
To: haskell-cafe@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

                                                                                
  
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to