[GHC] #13441: Type inference failure in bidirectional pattern synonym and GADT pattern match
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple PatternSynonyms | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- In my musings in preparation toward teaching my undergrads about GADTs, I tried defining the usual old `Vec` in terms of `FList`s (definition below) and pattern synonyms. Here is the code: {{{ {-# LANGUAGE ScopedTypeVariables, PatternSynonyms, DataKinds, PolyKinds, GADTs, TypeOperators, TypeFamilies #-} module VecFList where import Data.Functor.Identity data FList f xs where FNil :: FList f '[] (:@) :: f x -> FList f xs -> FList f (x ': xs) data Nat = Zero | Succ Nat type family Length (xs :: [k]) :: Nat where Length '[] = Zero Length (_ ': xs) = Succ (Length xs) type family Replicate (n :: Nat) (x :: a) = (r :: [a]) where Replicate Zero _ = '[] Replicate (Succ n) x = x ': Replicate n x type Vec n a = FList Identity (Replicate n a) pattern Nil :: forall n a. n ~ Length (Replicate n a) => n ~ Zero => Vec n a pattern Nil = FNil pattern (:>) :: forall n a. n ~ Length (Replicate n a) => forall m. n ~ Succ m => a -> Vec m a -> Vec n a pattern x :> xs <- Identity x :@ xs where x :> xs = Identity x :@ xs }}} This fails with {{{ /Users/rae/temp/Bug.hs:30:34: error: • Could not deduce: m0 ~ Length xs arising from the "provided" constraints claimed by the signature of ‘:>’ from the context: n ~ Length (Replicate n a) bound by the type signature of pattern synonym ‘:>’ at /Users/rae/temp/Bug.hs:30:11-12 • In the declaration for pattern synonym ‘:>’ • Relevant bindings include xs :: FList Identity xs (bound at /Users/rae/temp/Bug.hs:30:34) }}} If I comment out the last two lines (the "explicitly bidirectional" part), compilation succeeds, even though the reported error is on the first line of the `:>` pattern synonym definition (the pattern part). Also, the following separate declaration compiles without incident: {{{ (>>>) :: forall n a. n ~ Length (Replicate n a) => forall m. n ~ Succ m => a -> Vec m a -> Vec n a x >>> xs = Identity x :@ xs }}} I believe the original program should compile, and should continue to compile if I replace the `<-` in the patsyn definition with `=`. For the curious: I tried putting an injectivity annotation on `Replicate` to avoid those `n ~ Length (Replicate n a)` constraints, but type family injectivity just isn't strong enough. Also, I'm not at all sure this definition is any use. But the behavior I report above shouldn't happen, regardless. Reproducible in HEAD. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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 Iceland_jack): * cc: Iceland_jack (added) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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 Simon Peyton Jones <simonpj@…>): In [changeset:"7c7479d047113a0cbf237c864d403bb638ca0241/ghc" 7c7479d0/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="7c7479d047113a0cbf237c864d403bb638ca0241" Fix explicitly-bidirectional pattern synonyms This partly fixes Trac #13441, at least for the explicitly bidirectional case. See Note [Checking against a pattern signature], the part about "Existential type variables". Alas, the implicitly-bidirectional case is still not quite right, but at least there is a workaround by making it explicitly bidirectional. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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 bgamari): * status: new => merge * milestone: => 8.2.1 Comment: It seems like this should probably be merged, yes? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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): Yes. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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 Simon Peyton Jones <simonpj@…>): In [changeset:"b5c81203d047293f54c4e89ac70d505197968cb3/ghc" b5c81203/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="b5c81203d047293f54c4e89ac70d505197968cb3" Complete the fix for #13441 (pattern synonyms) Do not attempt to typecheck both directions of an implicitly-bidirectional pattern synonym simultanously, as we were before. Instead, the builder is typechecked when we typecheck the code for the builder, which was of course happening already, even in both bidirectional cases. See Note [Checking against a pattern signature], under "Existential type variables". }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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): * status: merge => new Comment: Probably worth merging this too. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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): * status: new => merge -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: | Keywords: | PatternSynonyms 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 bgamari): comment:2 merged to `ghc-8.2` as 8a857f50c5922365c71d07cb403f5c46a75b204e. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13441: Type inference failure in bidirectional pattern synonym and GADT pattern match -------------------------------------+------------------------------------- Reporter: goldfire | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: | PatternSynonyms 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 bgamari): * status: merge => closed * resolution: => fixed Comment: comment:5 merged as 765219d949abc4afd4d6eb2c13c2dfb35a392249. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13441#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC