
To broaden this a bit, it is worth remembering that ''the main `foldr/build` rule itself is unsound in the presence of `seq`''. See, for example, the [http://www.haskell.org/haskellwiki/Correctness_of_short_cut_fusion#In_the_pr... Haskell wiki page].
This is not nice. The "right" solution is for `seq` to be an operation of a type class, something that was the case in Haskell originally, and
#9495: Do What I Mean RULES for foldr2 look shady -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.4 Component: | Version: 7.8.3 libraries/base | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Runtime | Related Tickets: crash | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:6 simonpj]: then changed after ''extensive'' debate on the Haskell committee.
So currently we are stuck in the unsatisfactory situation that certain
optimisations, which have a generally very beneficial effect on performance, can change termination behaviour. Eta reduction/expansion is another.
In that general context I don't have a strong opinion about the `foldr2`
question. I'd consult the Core Libraries Committee.
Simon
Without a doubt, these are not nice. But we generally keep the danger under control. We make the compiler prove that eta expansion is safe before applying it (I'm not sure what happens with eta reduction). We hide `build` away from the normal user libraries to allow us to pretend it will only be used by people who have read the necessary documentation (yes, that documentation may need some improvement). But `foldr2`, `zipWith`, and `zip` are completely exposed, right in the Prelude, along with a `filter` for them to crash with! David -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9495#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler