[GHC] #8581: Add support for explicitly-bidirectional pattern synonyms

GHC ghc-devs at haskell.org
Sun Dec 1 04:31:56 UTC 2013


#8581: Add support for explicitly-bidirectional pattern synonyms
------------------------------------+-------------------------------------
       Reporter:  cactus            |             Owner:  cactus
           Type:  feature request   |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  Compiler          |           Version:
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
     Difficulty:  Unknown           |         Test Case:
     Blocked By:  5144              |          Blocking:
Related Tickets:                    |
------------------------------------+-------------------------------------
 Some patterns cannot, by themselves, be turned over into an expression, so
 they have to be defined as unidirectional. Maybe the most trivial example
 would be

 {{{
 pattern P -> _
 }}}

 Sometimes, however, it would be desirable to give an explicit way of
 turning these pattern synonyms into expressions. The PatternSynonyms wiki
 page has this example:

 {{{
 import qualified Data.Sequence as Seq

 pattern Empty -> (Seq.viewl -> Seq.EmptyL)
 pattern x :< xs -> (Seq.viewl -> x Seq.:< xs)
 pattern xs :> x -> (Seq.viewr -> xs Seq.:> x)

 }}}

 It would make a ton of sense to be able to use this cons/snoc notation as
 "constructors" for `Seq`s.

 The proposed syntax for this

 {{{
 pattern x :< xs -> (Seq.viewl -> x Seq.:< xs) where
     x :< xs = x Seq.<| xs
 }}}

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


More information about the ghc-tickets mailing list