[GHC] #8582: Record syntax for pattern synonyms

GHC ghc-devs at haskell.org
Wed Sep 16 12:01:47 UTC 2015


#8582: Record syntax for pattern synonyms
-------------------------------------+-------------------------------------
        Reporter:  cactus            |                   Owner:  mpickering
            Type:  feature request   |                  Status:  new
        Priority:  high              |               Milestone:  8.0.1
       Component:  Compiler          |                 Version:
      Resolution:                    |                Keywords:
                                     |  PatternSynonyms
Operating System:  Unknown/Multiple  |            Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:  5144              |                Blocking:
 Related Tickets:                    |  Differential Revisions:  Phab:D1152
-------------------------------------+-------------------------------------

Comment (by simonpj):

 I'm sorry but I'm honestly not sure what the specification of the new
 feature is.

 The [wiki:PatternSynonyms#Design design subsection] is helpful, but it
 uses only one
 example, and I can't tell what is supposed to happen in general.

 Let's try this.  In general, a pattern synonym should behave exactly like
 its
 expansion.  So given
 {{{
 pattern P x = (x, True)
 }}}
 these two functions should behave the same:
 {{{
 f1 (P False) = "yes"
 f2 (P True)  = "no"

 f2 (False,True) = "yes"   -- Replace (P pat) by its expansion
 f2 (True, True) = "no"
 }}}
 (Actually they are not quite the same; see
 [wiki:PatternSynonyms#DynamicSemantics dynamic semantics subsection].  But
 close enough for now.)

 But for your proposal, given
 {{{
 pattern Foo{bar, baz} = (bar, baz)
 }}}
 how, exactly should pattern matches on `Foo` expand?  I can't tell.

 Another way to get at this question would be to look at
 [https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-580003.17
 Section 3.17 of the langauge definition].  What changes, precisely, are
 required to accommodate pattern synonyms?  (It's a deficiency in the
 current user manual that it does not say.)

 To give the idea, here is my first stab at extending 3.17.2.  Add an extra
 item to the list, saying

  * To match a pattern `P p1 .. pn` against a value, where `P` is a pattern
 synonym defined by `pattern P x1 .. xn = prhs`,
    * first match the pattern `prhs` against the value, thereby binding
 `x1`..`xn`.
    * and then match `p1` agianst `x1`, `p2` against `x2`, and so on in
 sequence.

 A similar modification to 3.17.3 would be needed.

 Now, how would you change those words if your proposal was adopted?

 Thanks.

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


More information about the ghc-tickets mailing list