haskell
Haskell jaror Now 100%

TIL: wrapping list comprehension in a function can prevent fusion

This fuses:

[(x, y) | x <- [0 .. 10], y <- [0 .. 10]]

But this does not:

liftA2 (,) [0 .. 10] [0 .. 10]

Because the latter inlines to:

let xs = [0..10]; ys = [0..10] in xs >>= \x -> ys >>= \y -> (x, y)

And GHC is afraid to push the ys binding into the \x -> ... lambda because that might duplicate the work of evaluating [0..10]. Even though in the end fusing everything would be beneficial.

See: https://gitlab.haskell.org/ghc/ghc/-/issues/24663

1
1
Comments 1