
#11715: Constraint vs * -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: high | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.1-rc1 checker) | Resolution: | Keywords: Typeable 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 int-index): Replying to [comment:41 goldfire]:
Now, understanding `with 3 $ with 4 $ ...` is easy: the `...` will have access to `4`, which shadows `3`.
I am very suspicious about shadowing semantics. I'd rather see `Int` treated like any other constraint, no different than `Given Int`. We don't have shadowing semantics for `Given Int`: the example from comment:24 demonstrates that the first dictionary was picked, not the second one (and this behavior can change with a minor compiler version). Once again, it moves us further down the road where we admit that there can be more than one value of one type to the left of `=>`. There shouldn't be. Well-defined semantics for using nested `incoherentWith` will encourage people to do so. In Edward's parlance, the `Constraint` category is thin; let's not change it. I also couldn't find any mention of shadowing in the "Implicit parameters" section of the GHC user guide. Could you point me where I can read how it gets resolved? As far as I know, implicit parameters use the `IP` class under the hood, but GHC seems to consistently choose the innermost binding (in contrast to `Given`, where the outermost binding prevails): {{{#!hs GHCi, version 8.1.20160813: http://www.haskell.org/ghc/ :? for help Prelude> :set -XImplicitParams Prelude> :set -XGADTs Prelude> data X where X :: (?x :: Int) => X Prelude> f :: X -> X -> Int; f X X = ?x Prelude> f (let ?x = 1 in X) (let ?x = 2 in X) 2 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11715#comment:42 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler