Give more guratees about ImplicitParams extension
Summary
Location of documentation issue: the GHC user's guide
GHC's constraint solver is able to do whatever it wants: reorder constraints, take one from the global scope and all other things. This behavior obviously doesn't work for the ImplicitParams
and GHC has the special behavior to catch it, but this special behavior is undocumented in GHC user's guide, i.e. GHC don't give the guarantee to the user that it will not reorder something (since GHC user's guide is only GHC specification).
Proposed improvements or changes
There are two cases that I want to see in the Implicit-parameter bindings section:
let ?foo = 1 in let ?foo = 2 in ?foo
This code will return number 2 and this is what everyone would expect, but it doesn't established in the user's guide.
- and the more tricky example:
data T where
MkT :: (?foo :: Int) => T
f :: T -> T -> Int
f MkT MkT = ?foo
Which value is selected, from the first MkT
or from the second one? GHC now takes from the second one, I can expect in since f MkT MkT = ...
is just a sugar over f = \MkT -> \MkT -> ...
, but there is another intuition: f a a = ...
should be a compile time error.
Since I don't want to propose new constraint solver behavior, I'm asking for adding new rule into GHC user's guide about that GHC will select ?foo
from the second binding.