[GHC] #14748: Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int))

#14748: Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int)) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: Keywords: | Operating System: Unknown/Multiple QuantifiedConstraints wipT2893 | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- (based on WIP [https://phabricator.haskell.org/D4353 -XQuantifiedConstraints]) Could GHC infer the context for deriving `Data (Foo f)` (#12245)? {{{#!hs data Foo f = Foo (f Bool) (f Int) deriving stock Data {- Generates: instance (Typeable f, (forall xx. Data xx => Data (f xx))) => Data (Foo f) -} }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14748 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14748: Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int)) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: | QuantifiedConstraints wipT2893, | deriving 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: QuantifiedConstraints wipT2893 => QuantifiedConstraints wipT2893, deriving Comment: I'm not sure. When doing {{{ data T a = MkT a [a] deriving( Eq ) }}} the deriving mechanism says "oh, we need `Eq` on each field, that is `Eq a, Eq [a]`". Then it simplifies that to arrive at the instance context. For your example, it'd say "I need `Data (f Bool), Data (f Int)` and then get stuck. There are two ways to get unglued. One is simply to put those in the instance context {{{ instance (Data (f Int), Data (f Bool)) => Data (Foo f) where ... }}} The other is to use quantified constraints. It's not clear which is best in general. And even figuring out the appropriate quantified-constraint generalisation of a set of ground constraints is far from trivial. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14748#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14748: Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int)) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: Resolution: | Keywords: | QuantifiedConstraints wipT2893, | deriving 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 RyanGlScott): I too am skeptical that there is a robust, systematic way to do what you're seeking. I think the intent of https://ghc.haskell.org/trac/ghc/ticket/12245#comment:1 was to combine quantified constraints with `StandaloneDeriving`, not have the quantified constraints be inferred. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14748#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14748: Infer context for Data instance of (data Foo f = Foo (f Bool) (f Int)) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: Resolution: wontfix | Keywords: | QuantifiedConstraints wipT2893, | deriving 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 RyanGlScott): * status: new => closed * resolution: => wontfix Comment: Closing, since this is neither how we want to tackle this problem, nor a solution that will work most of the time, as per comment:1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14748#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC