[GHC] #11658: Type synonym with context in pattern synonym

#11658: Type synonym with context in pattern synonym -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs pattern :: (Num a, Eq a) => a pattern Fiskur = 42 }}} unlike {{{#!hs type Diskur a = Num a => a fiskur :: Num a => a fiskur = 42 }}} we cannot write {{{#!hs type Fugl a = (Num a, Eq a) => a pattern Fiskur :: Fugl a pattern Fiskur = 42 -- Exp.hs:54:18-19: error: … -- • No instance for (Eq a) arising from a pattern -- Possible fix: -- add (Eq a) to the context of -- the type signature for pattern synonym ‘Fiskur’: -- Fugl a -- • In the pattern: 42 -- In the declaration for pattern synonym ‘Fiskur’ -- Compilation failed. }}} Given that the story of pattern synonym contexts is more complicated than usual patterns given provided constraints, I know there are other issues (#11524, #10928). ---- For fun why not type synonym with provided and required constraints: {{{#!hs data T a where MkT :: (Show b) => a -> b -> T a f1 :: (Eq a, Num a) => T a -> String f1 (MkT 42 x) = show x type MKNUMPAT a b = (Num a, Eq a) => (Show b) => b -> T a -- pattern ExNumPat :: (Num a, Eq a) => (Show b) => b -> T a pattern ExNumPat :: MKNUMPAT a b pattern ExNumPat x = MkT 42 x }}} What would that mean in a regular type signature? `CE := CP + CR` where `EXNUMPAT a b` means the same as `EXNUMPAT' a b`? (#8581) {{{#!hs type MKNUMPAT' a b = (Num a, Eq a, Show b) => b -> T a -- This works: mkNumPat :: MKNUMPAT a b mkNumPat = ExNumPat }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11658 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11658: Type synonym with context in pattern synonym -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: 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): While I understand why the syntax might suggest that this is a good idea. I don't support this proposal. The thing after `pattern Blah ::` is '''not''' a type. It's a pattern synonym type, which is something else. Of course, type synonyms should be allowed in pattern synonym types, but we shouldn't confuse the normal `=>` that might appear in a type synonym with the `=>` that appears in a pattern synonym type. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11658#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC