Unsure of how to get the right evaluation order
- by Matt Fenwick
I'm not sure what the difference between these two pieces of code is (with respect to x), but the first one completes:
$ foldr (\x y -> if x == 4 then x else x + y) 0 [1,2 .. ]
10
and the second one doesn't (at least in GHCi):
$ foldr (\x (y, n) -> if x == 4 then (x, n) else (x + y, n + 1)) (0, 0) [1,2 .. ]
.......
What am I doing wrong…