[GHC] #14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified

#14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified -------------------------------------+------------------------------------- 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 came up on a [https://www.reddit.com/r/haskell/comments/8257mz/how_quantifiedconstraints_c... reddit thread], {{{#!hs {-# Language QuantifiedConstraints #-} class (forall aa. Functor (bi aa)) => Bifunctor bi where first :: (a -> a') -> (bi a b -> bi a' b) bimap :: Bifunctor bi => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = first f . fmap g }}} This is the type we want for `bimap` even if we mix & match `Bifunctor` and `Functor`. We already know that we can `fmap @(bi xx)` for any `xx` but this is not the inferred type. Instead GHC infers a type (tidied up) with a superfluous `Functor` constraint {{{#!hs bimap :: (Bifunctor bi, Functor (bi a)) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') }}} Indeed post-composing with a superfluous `fmap @(bi a')` incurs yet another `Functor` constraint {{{#!hs bimap :: (Bifunctor bi, Functor (bi a), Functor (bi a')) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = fmap id . first f . fmap g }}} A terminology question, I'm not sure how to phrase what GHC isn't doing to the `Functor` constraints: ‘discharge’? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14896 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified -------------------------------------+------------------------------------- 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: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: Old description:
This came up on a [https://www.reddit.com/r/haskell/comments/8257mz/how_quantifiedconstraints_c... reddit thread],
{{{#!hs {-# Language QuantifiedConstraints #-}
class (forall aa. Functor (bi aa)) => Bifunctor bi where first :: (a -> a') -> (bi a b -> bi a' b)
bimap :: Bifunctor bi => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = first f . fmap g }}}
This is the type we want for `bimap` even if we mix & match `Bifunctor` and `Functor`. We already know that we can `fmap @(bi xx)` for any `xx` but this is not the inferred type.
Instead GHC infers a type (tidied up) with a superfluous `Functor` constraint
{{{#!hs bimap :: (Bifunctor bi, Functor (bi a)) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') }}}
Indeed post-composing with a superfluous `fmap @(bi a')` incurs yet another `Functor` constraint
{{{#!hs bimap :: (Bifunctor bi, Functor (bi a), Functor (bi a')) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = fmap id . first f . fmap g }}}
A terminology question, I'm not sure how to phrase what GHC isn't doing to the `Functor` constraints: ‘discharge’?
New description: This came up on a [https://www.reddit.com/r/haskell/comments/8257mz/how_quantifiedconstraints_c... reddit thread], {{{#!hs {-# Language QuantifiedConstraints #-} class (forall aa. Functor (bi aa)) => Bifunctor bi where first :: (a -> a') -> (bi a b -> bi a' b) bimap :: Bifunctor bi => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = first f . fmap g }}} This is the type we want for `bimap` even if we mix & match `Bifunctor` and `Functor`. We already know that we can `fmap @(bi xx)` for any `xx` but this is not the inferred type. Instead GHC infers a type (tidied up) with a superfluous `Functor` constraint {{{#!hs bimap :: (Bifunctor bi, Functor (bi a)) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') }}} Indeed post-composing with a superfluous `fmap @(bi a') id` incurs yet another `Functor` constraint {{{#!hs bimap :: (Bifunctor bi, Functor (bi a), Functor (bi a')) => (a -> a') -> (b -> b') -> (bi a b -> bi a' b') bimap f g = fmap id . first f . fmap g }}} A terminology question, I'm not sure how to phrase what GHC isn't doing to the `Functor` constraints: ‘discharge’? -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14896#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified -------------------------------------+------------------------------------- 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): Interesting. When inferring a type, GHC finds all the unsolved constraints. Supopse they are `(Eq a, Ord a)`. Then it minimises them in a very simple-minded way, dicarding any that are implied by the superclasses of some other constraint. So, since `Eq a` is a superclass of `Ord a`, we discard it. So we infer a type like {{{ f :: Ord a => blah }}} Now suppose we have `(Bifunctor bi, Functor (bi a))`. Yes, the latter is implied by the former, but now it is much more indirect. I'm not yet sure how to do a better job here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14896#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified -------------------------------------+------------------------------------- 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/14896#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14896: QuantifiedConstraints: GHC does doesn't discharge constraints if they are quantified -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: low | 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 dfeuer): * priority: normal => low Comment: Reducing the priority for now. I'll bump it back up if someone comes up with a situation where this actually prevents valid code from compiling. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14896#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC