#2467: orphan instance warnings are badly behaved
---------------------------------+------------------------------------------
    Reporter:  duncan            |        Owner:                  
        Type:  bug               |       Status:  new             
    Priority:  normal            |    Milestone:  6.12 branch     
   Component:  Compiler          |      Version:  6.8.2           
    Severity:  normal            |   Resolution:                  
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Comment (by Syzygies):

 Reflecting further, I noticed that these manual sections go together
 nicely:

 > 5.1.2. Command line options in source files

 > 5.6.12. Orphan modules and instance declarations

 In particular, the phrase stands out

 > in some circumstances, the OPTIONS_GHC pragma is the Right Thing.

 Moving ''-fno-warn-orphans'' from the command line to a particular orphan
 file is idiomatic GHC for my situation. I already have a module containing
 helper functions such as

 {{{
 foldrC ∷ (Foldable d, Foldable e, Foldable f) ⇒
   (c a → d (e (f a))) → (a → b → b) → b → c a → b
 foldrC gi h y = foldr (flip $ foldr (flip $ foldr h)) y . gi
 }}}

 for defining deep Foldable instances that go through a newtype and three
 layers of structure.
 {{{
 instance Foldable ((,) a) where foldr f z (_,y) = f y z
 }}}
 can arise as one of those layers, so this is a natural place to put such
 orphans.

 Instance declarations are just as hard on the programmer as on GHC itself.
 For example, ''Functor ((,) a)'' is documented in Control.Monad, but
 importing Control.Monad doesn't expose this instance.  ''Functor ((,) a)''
 is not documented in Data.Foldable, but importing Data.Foldable does
 expose this instance. This left me perplexed as to why I could define deep
 Functor instances that relied on ''Functor ((,) a)'', but I couldn't write
 ''foldr (+) 2 (1,2)'' in ghci. I was left believing that this was some
 compiler magic I didn't understand, until I started using ''ghc --show-
 iface'', and spelunking the library source code.

 If I could have one wish related to instance declarations, it wouldn't
 have to do with these orphan warnings, but rather with better control over
 duplicate instance declarations. For example, I can't import Data.Foldable
 and at the same time try to redefine ''instance Monad ((->) a)''; there is
 no ''hiding'' clause that affects instances. Perhaps this is a moot point,
 as I have yet to find a standard library instance that has a reasonable
 alternative definition. One can imagine Haskell' providing missing
 instances anytime it can prove that there is only one possible definition.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2467#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to