foldr oddity

Frodo Chao frodogreat at gmail.com
Wed Oct 12 10:44:06 CEST 2011


Hi,

Thank you all for you replies.

I think now I understand Haskell better.

Best regards,
Frodo

2011/10/12 Frodo Chao <frodogreat at gmail.com>

> Hi,
>
> I came upon this when playing with foldr and filter. Compare the two
> definitions:
>
> testr  n = foldr (\x y -> x && y) True [t | (_, t) <- zip [1 .. n] [True,
> True ..]]
> testr' n = foldr (\x y -> y && x) True [t | (_, t) <- zip [1 .. n] [True,
> True ..]]
>
> I tried these functions on ghci (The Glorious Glasgow Haskell Compilation
> System, version 7.0.3), and get the following results (with :set +s):
>
> testr 1000000 => True
> (0.01 secs, 7920832 bytes)
> testr' 1000000 => True
> (8.72 secs, 446585344 bytes)
>
> This bizarre (at least to me) behavior also applies to ||. Should I mind
> the orderings of the parameters (especially the accumulator) in the function
> passed to foldr?
>
> Thak you for reading.
>
> Sincerely yours,
> Frodo Chao
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20111012/1f1427e7/attachment-0001.htm>


More information about the Glasgow-haskell-users mailing list