Does GHC optimize the monoid operation over mempty?

If I write an instance of Semigroup with a horrible complexity for its operation (<>), will GHC know that mempty <> x = x x <> mempty = x and avoid computing (<>) ? I’m also interested in how you got that information, and, if this optimization does not exits, whether this could be done… Read More Does GHC optimize the monoid operation over mempty?