[GHC] #14958: QuantifiedConstraints: Doesn't apply implication for existential?

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 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: -------------------------------------+------------------------------------- This fails {{{#!hs {-# Language GADTs, RankNTypes, ConstraintKinds, QuantifiedConstraints, AllowAmbiguousTypes #-} data Foo where Foo :: (forall x. ((forall y. cls y => Num y), cls x) => x) -> Foo a :: Foo a = Foo 10 }}} {{{ $ ... -ignore-dot-ghci /tmp/Optic.hs GHCi, version 8.5.20180128: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( /tmp/Optic.hs, interpreted ) /tmp/Optic.hs:7:9: error: • Could not deduce (Num x) arising from the literal ‘10’ from the context: (forall y. cls0 y => Num y, cls0 x) bound by a type expected by the context: forall x. (forall y. cls0 y => Num y, cls0 x) => x at /tmp/Optic.hs:7:5-10 Possible fix: add (Num x) to the context of a type expected by the context: forall x. (forall y. cls0 y => Num y, cls0 x) => x • In the first argument of ‘Foo’, namely ‘10’ In the expression: Foo 10 In an equation for ‘a’: a = Foo 10 | 7 | a = Foo 10 | ^^ Failed, no modules loaded. Prelude> }}} GHC knows that `cls ~=> Num` but still GHC cannot deduce `Num x` from `cls x`. ---- The reason for trying this is creating a `newtype` for optics where we still get subsumption {{{#!hs {-# Language GADTs, RankNTypes, ConstraintKinds, QuantifiedConstraints, AllowAmbiguousTypes, ApplicativeDo, TypeOperators, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, PolyKinds, FlexibleContexts #-} data Optic cls s a where Optic :: (forall f. cls f => (a -> f a) -> (s -> f s)) -> Optic cls s a class (forall x. f x => g x) => (f ~=> g) instance (forall x. f x => g x) => (f ~=> g) _1 :: cls ~=> Functor => Optic cls (a, b) a _1 = Optic $ \f (a, b) -> do a' <- f a pure (a', b) lens_1 :: Optic Functor (a, b) a lens_1 = _1 trav_1 :: Optic Applicative (a, b) a trav_1 = _1 }}} and I wanted to move `cls ~=> Functor` into the `Optic` type itself. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 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 simonpj): This is to do with overlapping instances. We have {{{ Foo :: (forall x. ((forall y. cls y => Num y), cls x) => x) -> Foo }}} So from the expression `Foo 10` we have: Given: {{{ Skolems: x Given: d1: forall y. cls0 y => Num y d2: cls0 x Wanted: Num x }}} Here `cls0` is a unification variable; we don't yet know what it'll tur out to be, and indeed (given the type of `Foo`) it's ambiguous. When trying to solve `Num x` GHC doesn't want to use `d1`, because that make a commitment to solve its sub-goals. If `cls0` turned out to be `Num`, an alternative would be to pick `d2`. So it simply refrains from choosing. (The error message doesn't make this clear, I know.) If you fix `cls0` all is well. For example: {{{ data Foo (cls :: * -> Constraint) where Foo :: forall cls. (forall x. ((forall y. cls y => Num y), cls x) => x) -> Foo cls a :: Foo Fractional a = Foo 10 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 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): Ah! That makes perfect sense, we can specify a `Proxy cls` and not change the kind of `Foo` although I'm not sure this gives me what I want {{{#!hs data Foo where Foo :: Proxy cls -> (forall x. ((forall y. cls y => Num y), cls x) => x) -> Foo a :: Foo a = Foo (Proxy :: Proxy Num) 10 b :: Foo b = Foo (Proxy :: Proxy Fractional) 10.0 }}} I have a draft ready for an overview of this extension from ticket:14840#comment:6, should I email it to you? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 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 simonpj):
I have a draft ready for an overview of this extension from ticket:14840#comment:6, should I email it to you?
A draft of what? A blog post? If so, I suggest you just post it! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 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): Ah I started writing it as a paper -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 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 simonpj): Even better! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14958: QuantifiedConstraints: Doesn't apply implication for existential? -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: | QuantifiedConstraints 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): * keywords: QuantifiedConstraints, wipT2893 => QuantifiedConstraints -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14958#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC