[GHC] #8583: Associated pattern synonyms

GHC ghc-devs at haskell.org
Fri Jul 17 18:02:40 UTC 2015


#8583: Associated pattern synonyms
-------------------------------------+-------------------------------------
        Reporter:  cactus            |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |  PatternSynonyms
 Type of failure:  None/Unknown      |            Architecture:
      Blocked By:  5144              |  Unknown/Multiple
 Related Tickets:                    |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by bgamari:

Old description:

> The PatternSynonyms wiki page has a section on (typeclass-)associated
> pattern synonyms:
>
> {{{#!hs
> class ListLike l where
>       pattern Nil :: l a
>       pattern Cons :: a -> l a -> a
>       isNil :: l a -> Bool
>       isNil Nil = True
>       isNil (Cons _ _) = False
>       append :: l a -> l a -> l a
>
>    instance ListLike [] where
>       pattern Nil = []
>       pattern Cons x xs = x:xs
>       append = (++)
>
>    headOf :: (ListLike l) => l a -> Maybe a
>    headOf Nil = Nothing
>    headOf (Cons x _) = Just x
> }}}

New description:

 The PatternSynonyms wiki page has a section on (typeclass-)associated
 pattern synonyms:

 {{{#!hs
 class ListLike l where
       pattern Nil :: l a
       pattern Cons :: a -> l a -> a
       isNil :: l a -> Bool
       isNil Nil = True
       isNil (Cons _ _) = False
       append :: l a -> l a -> l a

 instance ListLike [] where
       pattern Nil = []
       pattern Cons x xs = x:xs
       append = (++)

 headOf :: (ListLike l) => l a -> Maybe a
 headOf Nil = Nothing
 headOf (Cons x _) = Just x
 }}}

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8583#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list