Scanl expressed as fold Inspired by the learn you a haskell exercise to express map with fold I wrote an implementation of scanl by means of a fold.

scanl2 :: (b -&gt; a -&gt; b) -&gt; b -&gt; [a] -&gt; [b]
scanl2 f z xs = reverse $ foldl (\a x -&gt; (f (head a) x): a) [z] xs


I have the idea that in terms of performance it kinda is up to par with standard scanl but I am wondering whether I could improve anything both in terms of performance, idiomacy, style, etc. I am a Haskell novice with modest functional programming (Scala, some Clojure) background.
Using reverse is generally a bad idea for performance — especially since Haskell lists can be infinite!  Observe:

*Main&gt; let triangularNumbers = scanl (+) 0 [1, 2 ..]
*Main&gt; let triangularNumbers2 = scanl2 (+) 0 [1, 2 ..]
*Main&gt; take 5 triangularNumbers
[0,1,3,6,10]
*Main&gt; take 5 triangularNumbers2          -- hangs forever