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

GHC ghc-devs at haskell.org
Sun Feb 28 22:16:43 UTC 2016


#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


More information about the ghc-tickets mailing list