[Haskell-cafe] Instance match surprise
hyarion at iinet.net.au
Mon Feb 1 20:34:42 UTC 2016
On 2 February 2016 7:22:31 AM AEDT, "Wojtek Narczyński" <wojtek at power.com.pl> wrote:
>On 01.02.2016 20:19, Imants Cekusins wrote:
>> instance (Eq a, Eq q, Typeable a, Typeable q, AtmAcct a, Against q)
>> Match a q where
>> ANY is q
>> instance Against ANY
>But I require q to be Eq and Typeable, and ANY is none of those two?
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
But there *could* be other instances the compiler just can't see at the moment (because it's in another module that's not imported). Someone else could then import this module and that other module and observe inconsistent instances.
To avoid that problem, the type class system *never* commits to "negative" information; if an instance choice is only valid because there *isn't* a possible instance in scope then that instance choice is not valid after all.
A consequence is that constraints on an instance have to be ignored when choosing an instance (they still might make the choice be an error after it is chosen, but they don't affect which instance is selected). And so an instance like:
... => Match a q
is the *only* possible instance you can write, since it will match everything regardless of the ... (unless you use overlapping instances).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe