Today I learnt that GHC has an incredible facility to teach it optimisations applicable to your code: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/rewrite-rules.html