[GHC] #14266: AllowAmbiguousTypes doesn't play well with default class methods

GHC ghc-devs at haskell.org
Thu Sep 21 19:45:48 UTC 2017


#14266: AllowAmbiguousTypes doesn't play well with default class methods
-------------------------------------+-------------------------------------
        Reporter:  chris-martin      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by chris-martin:

Old description:

> This example does compile,
>
> {{{
> {-# LANGUAGE AllowAmbiguousTypes #-}
> {-# LANGUAGE ExplicitForAll #-}
>
> class A t where
>   f :: forall x m. Monoid x => t m -> m
>   f = undefined
>
> instance A [] where
>   f = undefined
> }}}
>
> and it seems that the following really ought to be equivalent to it,
> since all I have done is remove a method definition which is identical to
> the default:
>
> {{{
> {-# LANGUAGE AllowAmbiguousTypes #-}
> {-# LANGUAGE ExplicitForAll #-}
>
> class A t where
>   f :: forall x m. Monoid x => t m -> m
>   f = undefined
>
> instance A []
> }}}
>
> But instead GHC 8.0.2 gives an error of "Could not deduce (Monoid x0)" on
> the instance declaration.
>
> (I've also posed the same question on stackoverflow:
> https://stackoverflow.com/q/46350839/402884.)

New description:

 This example does compile,

 {{{
 {-# LANGUAGE AllowAmbiguousTypes #-}
 {-# LANGUAGE ExplicitForAll #-}

 class A t where
   f :: forall x m. Monoid x => t m -> m
   f = undefined

 instance A [] where
   f = undefined
 }}}

 and it seems that the following really ought to be equivalent to it, since
 all I have done is remove a method definition which is identical to the
 default:

 {{{
 {-# LANGUAGE AllowAmbiguousTypes #-}
 {-# LANGUAGE ExplicitForAll #-}

 class A t where
   f :: forall x m. Monoid x => t m -> m
   f = undefined

 instance A []
 }}}

 But instead GHC 8.0.2 gives an error of "Could not deduce (Monoid x0)" on
 the instance declaration.

 (I've also first posed this as a question on stackoverflow:
 https://stackoverflow.com/q/46350839/402884.)

--

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


More information about the ghc-tickets mailing list