[GHC] #7624: Handling ImplicitParams in Instance Declaration
GHC
cvs-ghc at haskell.org
Fri Jan 25 15:10:14 CET 2013
#7624: Handling ImplicitParams in Instance Declaration
---------------------------------+------------------------------------------
Reporter: philipjf | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Documentation | Version: 7.6.1
Keywords: ImplicitParams | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: Documentation bug
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
Comment:
I think the issue is this. Consider this:
{{{
class C a where
op :: a -> a
instance (?x:[a]) => C [a] where
op _ = ?x
foo y xs = let ?x = [y]
in (length xs, op xs)
}}}
From the instance declaration we get a dictionary-constructing function
with type
{{{
dfunCList :: forall a. (?x:a) -> C [a]
}}}
What type should be inferred for `foo`? I can think of three. I give
there with their translation into System F so you can see what proof
strategy I've used to solve the constraints.
{{{
foo1 :: C [a] => b -> [a] -> [a]
foo1 a (d:C [a]) (y:b) (xs:[a])
= let _x = [y]
in (length a xs, op a d xs)
foo2 :: (?x:a} => b -> [a] -> [a]
foo2 a b (?x:a) (y:b) (xs:[a])
= let _x = [y]
in (length a xs, op a (dfunCList a ?x) xs)
foo3 :: a -> [a] -> [a]
foo3 a (y:a) (xs:[a])
= let ?x = [y]
in (length a xs, op a (dfunCList a ?x) xs)
}}}
Notice that there is no most-general type. It all depends when we make
use of the `dfunCList` dictionary construction, and, even when we have
done so, whether we take advantage of the local binding for `?x`. I
suppose we could just say "GHC will randomly decide which of these three
to pick, but its hardly satisfactory!
Adding implicit parameters as superclasses is at least as problematic,
perhaps more so.
In short, I'm unconvinced!
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7624#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list