[GHC] #10532: Unnecessary constraints when using overlapping instances

GHC ghc-devs at haskell.org
Tue Jun 16 19:09:26 UTC 2015


#10532: Unnecessary constraints when using overlapping instances
-------------------------------------+-------------------------------------
        Reporter:  MikeIzbicki       |                   Owner:
            Type:  bug               |                  Status:  closed
        Priority:  normal            |               Milestone:
       Component:  Compiler (Type    |                 Version:  7.10.1
  checker)                           |                Keywords:
      Resolution:  invalid           |            Architecture:
Operating System:  Unknown/Multiple  |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by goldfire):

 What would you like to happen when GHC sees `(f (3 :: Int))`? My guess is
 that you expect GHC to notice that there is an instance for `Foo Int`
 around and to use it. But if `f` had the type `a -> Int`, then there is
 nothing to tell GHC to go out and look for the instance. When we have `f
 :: Foo a => a -> Int`, it tells GHC to look for a `Foo` instance at call
 sites.

 If, on the other hand, you want `f` always to use the `Foo a` instance,
 then `IncoherentInstances` is the way to go.

 I don't see this as an issue of parametricity, but just one of a
 misunderstanding about what the type signature means.

 As for what happens when you omit the signature: You're hitting the
 monomorphism restriction. When I load this into GHCi:

 {{{
 {-# LANGUAGE FlexibleInstances, NoMonomorphismRestriction #-}

 class Foo a where foo :: a -> Int
 instance {-# OVERLAPS #-} Foo Int where foo = id
 instance {-# OVERLAPPABLE #-} Foo a where foo _ = 5

 f = foo
 }}}

 I get an inferred type for `f` of `Foo a => a -> Int`.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10532#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list