[Haskell-cafe] reversing big list with constant heap space used

Henning Thielemann lemming at henning-thielemann.de
Wed May 16 07:48:37 EDT 2007


On Wed, 16 May 2007, Sergey Perminov wrote:

> How to solve task of reversing big list with constant heap space used?

By avoiding 'reverse'?

> Amount of heap space used grows exponentially in following examples:
>
> 1:
> main = putStrLn.show.head $reverse [1..10000000]

Data.List.last



I think that in every particular case you have to find out how to avoid
'reverse'. Especially if you have two 'reverse's like in
   reverse . dropWhile p . reverse
 there are more efficient solutions.


More information about the Haskell-Cafe mailing list