warn-identities from newtype deriving

Evan Laforge qdunkan at gmail.com
Tue Mar 14 08:28:24 UTC 2017


I just noticed that if you derive Real for a Ratio.Rational newtype,
you get a warning:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import qualified Data.Ratio as Ratio
newtype X = X Ratio.Rational deriving (Eq, Ord, Num, Real)

You get a warning:

<no location info>: Warning:
    Call of toRational :: Rational -> Rational
      can probably be omitted
    (Use -fno-warn-identities to suppress this message)

I suppose the automatic Real instance uses toRational to, um, define
toRational?  In any case, the <no location info> is certainly a bug,
but it looks like ghc 8.0.2 has fixed it.  Aside from that, it would
be nice to automatically suppress warn-identities and unused code
warnings in general for automatically generated code that we don't
really have any control over and can't see in the source.

It's easily worked around with OPTIONS_GHC to turn off the warning,
but it's confusing the first time you see it.


More information about the Glasgow-haskell-users mailing list