Hi,
Thank you all for you replies.
I think now I understand Haskell better.
Best regards,
Frodo
2011/10/12 Frodo Chao
> 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,
> T
* Frodo Chao [2011-10-12 10:45:04+0800]
> 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] [Tr
Hi Frodo,
If you happen to have a memory consumption graph somewhere on the screen
you can see that while testr does not need considerable amounts of
memory, testr' does. This can also be seen by ghci’s output.
The reason is that with testr we are building something like
True && [thunk]
which the
* Daniel Peebles [2011-10-11 23:18:15-0400]
> Yeah, you should absolutely mind the order of the parameters (or more
> generally, when the operation isn't commutative), the strictness of the
> function's second parameter. In this case, both (&&) and (||) are strict in
> their first parameter, but b
Yeah, you should absolutely mind the order of the parameters (or more
generally, when the operation isn't commutative), the strictness of the
function's second parameter. In this case, both (&&) and (||) are strict in
their first parameter, but both "short circuit" if the first parameter is
False/T
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 Glori