[Haskell-cafe] timing question

Brad Larsen brad.larsen at gmail.com
Sun Aug 3 12:58:20 EDT 2008


Arie,

foldl1 is not strict in its function argument.  Using it will cause stack overflows for large lists.

For example:

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> foldl1 (+) [0..1000000]
*** Exception: stack overflow

foldl1' from Data.List is strict in its function argument, and is probably what you want.

See also <http://www.haskell.org/haskellwiki/Stack_overflow>.

Regards,
Brad Larsen


On Sun, 03 Aug 2008 07:06:40 -0400, Arie Groeneveld <bradypus at xs4all.nl> wrote:

> Sorry, should go the forum.
>
> Ok, thanks. In this case the list consists of 6-digit alphanumeric
> codes. So doing something like:
>
> foldl1 (\x y -> g y) xs
>
> will do the job?
>
>
> =@@i
>
>
> Bulat Ziganshin schreef:
>> Hello Arie,
>>
>> Sunday, August 3, 2008, 1:56:43 PM, you wrote:
>>
>> *Main>> last . f $ xs
>>
>> this way you will get only "spin" of list computed, not elements
>> itself. something like sum should be used instead
>>
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 





More information about the Haskell-Cafe mailing list