[GHC] #7066: isInstance does not work for compound types
GHC
ghc-devs at haskell.org
Tue Apr 15 14:00:07 UTC 2014
#7066: isInstance does not work for compound types
-------------------------------------+------------------------------------
Reporter: edsko | Owner: simonpj
Type: bug | Status: new
Priority: normal | Milestone: 7.8.3
Component: Template Haskell | Version: 7.4.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by mojojojo):
> Are you making the case for an actual change in the behaviour of the
current TH operations? The current reifyInstances is deliberately
primitive (a one-level lookup) so that other stuff can be built on top. Or
are you asking for some new functions in the Quasi monad; or new functions
in the template-haskell library?
Well. I consider the current behaviour of `reifyInstances`
counterintuitive, to say at very least. It took me quite some time of
debugging the library I was developing at the time, before I narrowed the
issue I was experiencing down to the unexpected behaviour of
`reifyInstances`. Only then did I get to googling and finally here to find
out that it's actually an intended behaviour, though misleadingly
documented.
Let's consider the use cases for that function. All I can imagine is
finding the instances, which then can be relied on as applicable to the
tested types. I can imagine no scenario, in which one would want to get
instances, which the typechecker would deny. Can you imagine any examples
of such a case?
Considering the above, I can only see the current behaviour of that
function as a bug. However I am not strongly opinionated about changing
that, especially since I've already published a solution. The
documentation however definitely should be updated to make the behaviour
of this function clear.
> It would help a lot to be clear precisely what the behaviour is supposed
to be when the types concerned contain type variables. Currently
reifyInstances returns all the instance whose heads unify with the
specified constraint. I've looked at your code and it's not clear to me
exactly what it does. Could you write a specification?
I've [https://github.com/nikita-volkov/th-instance-
reification/blob/master/src/THInstanceReification.hs#L36-L87 updated the
code] by covering it with extensive comments. [https://github.com/nikita-
volkov/th-instance-reification/blob/master/src/HTFTestSuite.hs The test
suite] should also be useful for clarifying the expected behaviour.
> I think it's arguable that what you really want is something like
> {{{isInstance :: Cxt -> Name -> [Type] -> Q Bool}}}
> return True if the constraint (C tys) is provable from the specifed
context. For example, you could ask, say isIntance [Show a, Num a] Foo
[Maybe a], to ask whether you can prove (Foo (Maybe a)) from (Show a, Num
a). For ground types you could give the empty Cxt.
Yes, this looks like it.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7066#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list