Changes between Version 24 and Version 25 of PatternSynonyms


Ignore:
Timestamp:
Dec 1, 2013 5:11:29 AM (21 months ago)
Author:
cactus
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PatternSynonyms

    v24 v25  
    6868The simplest form of pattern synonyms is the one from the examples above.  The grammar rule is:
    6969
    70 `pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `->` ''pat''
    71 
    72 `pattern` ''varid,,1,,'' ''consym'' ''varid,,2,,'' `->` ''pat''
     70`pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `<-` ''pat''
     71
     72`pattern` ''varid,,1,,'' ''consym'' ''varid,,2,,'' `<-` ''pat''
    7373
    7474 * Each of the variables on the left hand side must occur exactly once on the right hand side
     
    105105{{{
    106106   pattern Arrow :: Type -> Type -> Type
    107    pattern Arrow t1 t2 -> App "->" [t1, t2]
     107   pattern Arrow t1 t2 <- App "->" [t1, t2]
    108108}}}
    109109
     
    113113import qualified Data.Sequence as Seq
    114114
    115 pattern Empty -> (Seq.viewl -> Seq.EmptyL)
    116 pattern x :< xs -> (Seq.viewl -> x Seq.:< xs)
    117 pattern xs :> x -> (Seq.viewr -> xs Seq.:> x)
     115pattern Empty <- (Seq.viewl -> Seq.EmptyL)
     116pattern x :< xs <- (Seq.viewl -> x Seq.:< xs)
     117pattern xs :> x <- (Seq.viewr -> xs Seq.:> x)
    118118}}}
    119119
     
    151151
    152152{{{
    153     pattern Succ n -> n1 | let n = n1 -1, n >= 0
     153    pattern Succ n <- n1 | let n = n1 -1, n >= 0
    154154}}}
    155155
     
    158158This is the rationale for the most complicated synonyms, the bidirectional ones.  They provide two expansions, one for patterns and one for expressions.
    159159
    160 `pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `->` ''pat'' `where` ''cfunlhs'' ''rhs''
     160`pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `<-` ''pat'' `where` ''cfunlhs'' ''rhs''
    161161
    162162where ''cfunlhs'' is like ''funlhs'', except that the functions symbol is a ''conid'' instead of a ''varid''.
     
    164164Example:
    165165{{{
    166    pattern Succ n -> n1 | let n = n1-1, n >= 0 where
     166   pattern Succ n <- n1 | let n = n1-1, n >= 0 where
    167167      Succ n = n + 1
    168168}}}