warn-identities from newtype deriving

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

warn-identities from newtype deriving

Evan Laforge
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.
Glasgow-haskell-users mailing list
[hidden email]