[GHC] #14266: AllowAmbiguousTypes doesn't play well with default class methods
GHC
ghc-devs at haskell.org
Tue Oct 3 21:00:41 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: |
-------------------------------------+-------------------------------------
Comment (by goldfire):
I've been only loosely following along. But comment:15 has a very clear
"here is the code that should compile". And so I tried it. And it doesn't.
But of course it doesn't, as `df` has no way of knowing that the `Monoid
x` instance in scope in the instance definition for `f` is the one to use.
To bring the type variable `x` into scope, it's necessary to use
`InstanceSigs` so that you can write a type signature bringing `x` into
scope. (By the way, if you use an expression type signature, the problem
is no better.) What I argue should compile is this:
{{{#!hs
class A t where
f :: forall x m. Monoid x => t m -> m
instance A [] where
f :: forall x m. Monoid x => [m] -> m
f = df @[] @x
df :: forall t. A t => forall x m. Monoid x => t m -> m
df = undefined
}}}
But this, too, doesn't compile because of the "more-general-than" check in
`InstanceSigs`, which can't be informed about what to do for `x`. While I
don't see any technical complications with allowing the user to direct the
"more-general-than" check, I can't think of any concrete syntax that isn't
nightmarish.
Perhaps we're simply barking up the wrong tree here, though. Suppose I
could write
{{{#!hs
instance A [] where
f @x = df @[] @x
}}}
where `f @x` is a visible type pattern. That would bring the right `x`
into scope (no `InstanceSigs`!) And then the "more-general-than"
comparison is not needed.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14266#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list