maximum and minimum are not good consumers in ghc 9.8.1
Motivation
maximum and minimum are not good consumers in ghc 9.8.1 which results in poor performance. I think this is true in earlier ghc versions also.
Program that demonstrates this (first do: cabal install --lib list-fusion-probe) :
{-# OPTIONS_GHC -Wall #-}
import Data.List.Fusion.Probe (fuseThis)
-- must compile with -O for fuseThis to work
main :: IO ()
main = print $ maximum $ fuseThis ['a'..'z']
Put the preceding in a file called enh.hs
% ghc -O enh.hs
Loaded package environment from /Users/avie/.ghc/aarch64-darwin-9.8.1/environments/default
[1 of 2] Compiling Main ( enh.hs, enh.o ) [Source file changed]
[2 of 2] Linking enh [Objects changed]
ld: warning: ignoring duplicate libraries: '-lm'
% ./enh
enh: fuseThis: List did not fuse
CallStack (from HasCallStack):
error, called at ./Data/List/Fusion/Probe.hs:52:16 in lst-fsn-prb-0.1.0.8-6ea610f9:Data.List.Fusion.Probe
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.8.1
Change "maximum" to "minimum" to see this.
Proposal
Change maximum and minimum to be good consumers which will improve performance.