[GHC] #12647: Can't capture improvement of functional dependencies

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple FunctionalDependencies | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- [http://www.diku.dk/~paba/pubs/files/serrano15haskell-paper.pdf Type Families with Class, Type Classes with Family] discusses [https://gist.github.com/Icelandjack/5afdaa32f41adf3204ef9025d9da2a70#pdf- instance-improvement instance improvement] with the example {{{#!hs class Collection c e | c -> e where empty :: c add :: e -> c -> c instance Collection [a] a where empty :: [a] empty = [] add :: a -> [a] -> [a] add = (:) }}} I wondered how to express that `x ~ Int` can be deduced from `Collection [Int] x` using improvement, I first attempted using the [https://hackage.haskell.org/package/constraints constraints] machinery: {{{#!hs data Dict c where Dict :: c => Dict c newtype a :- b = Sub (a => Dict b) }}} but I'm not able to construct a term of type `Collection [Int] x :- (Int ~ x)` proving that `Collection [Int] x` entails `Int ~ x`: {{{ ghci> Sub Dict :: Collection [Int] x :- (Int ~ x) <interactive>:52:5: error: • Couldn't match type ‘x1’ with ‘Int’ arising from a use of ‘Dict’ ‘x1’ is a rigid type variable bound by an expression type signature: forall x1. Collection [Int] x1 :- Int ~ x1 at <interactive>:52:13 • In the first argument of ‘Sub’, namely ‘Dict’ In the expression: Sub Dict :: Collection [Int] x :- (Int ~ x) In an equation for ‘it’: it = Sub Dict :: Collection [Int] x :- (Int ~ x) }}} Is this due to overlapping instances or something? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Resolution: | Keywords: | FunctionalDependencies 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 goldfire): Functional dependencies, as implemented in GHC, are used purely for disambiguating otherwise-ambiguous variables. That's it! In particular, a "given" fundep goes unused. There is much room for improvement here, but it would take a dedicated soul, and quite likely an update to the core language, with proofs and possibly a paper. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Resolution: | Keywords: | FunctionalDependencies 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 Iceland_jack): Thanks for the response! Interesting, since I'm maintaining [https://gist.github.com/Icelandjack/5afdaa32f41adf3204ef9025d9da2a70 notes on type classes] what should I say about ''instance improvement'', that it's not supported by the compiler or is it more complicated? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Resolution: | Keywords: | FunctionalDependencies 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 goldfire): Instance improvement happens only when you have a "wanted" constraint -- that is, when you're typechecking a function call of `f` where `f` has a class constraint with a functional dependency. Does that help? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Resolution: | Keywords: | FunctionalDependencies 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 rwbarton): See related discussion at http://stackoverflow.com/questions/34645745/can-i-magic-up-type-equality- from-a-functional-dependency/, #11534, and various other Trac tickets linked from there. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12647: Can't capture improvement of functional dependencies -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: task | Status: new Priority: normal | Milestone: Component: None | Version: 8.0.1 Resolution: | Keywords: FunDeps Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: FunctionalDependencies => FunDeps -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12647#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC