Changes between Version 8 and Version 9 of PatternSynonyms


Ignore:
Timestamp:
Feb 26, 2012 9:18:59 PM (3 years ago)
Author:
xrchz
Comment:

minor typo-correction and rewording

Legend:

Unmodified
Added
Removed
Modified
  • PatternSynonyms

    v8 v9  
    99}}}
    1010Using this representations the arrow type looks like `App "->" [t1, t2]`.
    11 Here are functions to collect are all argument types of nested arrows and recognizing the `Int` type:
     11Here are functions that collect all argument types of nested arrows and recognize the `Int` type:
    1212{{{
    1313   collectArgs :: Type -> [Type]
     
    1818   isInt _ = False
    1919}}}
    20 Matching on the arrow type is both hard to read and error prone to write.
     20Matching on `App` directly is both hard to read and error prone to write.
    2121
    22 The proposal is to introduce a way to give pattern names:
     22The proposal is to introduce a way to give patterns names:
    2323{{{
    2424   pattern Arrow t1 t2 = App "->" [t1, t2]
     
    3535}}}
    3636
    37 Furthermore, the pattern synonym can also be used in expressions, e.g.,
     37Furthermore, pattern synonyms can also be used in expressions, e.g.,
    3838{{{
    3939   arrows :: [Type] -> Type -> Type
     
    4242
    4343== Simple pattern synonyms ==
    44 The simplest form of pattern synonyms is the one from the examples above.  The grammar rule is simply:
     44The simplest form of pattern synonyms is the one from the examples above.  The grammar rule is:
    4545
    4646`pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `=` ''patexp''
    4747
    48 where ''patexp'' is simply the intersection of the grammars for patterns and expression, i.e., those terms that are valid both as a pattern and as an expressions.
    49  * Each of the variables on the left hand side must occur exactly one on the right hand side, and these are the only variables that can be mention on the right hand side. 
     48where ''patexp'' is the intersection of the grammars for patterns and expression, i.e., those terms that are valid both as a pattern and as an expression.
     49 * Each of the variables on the left hand side must occur exactly once on the right hand side, and these are the only variables that can occur on the right hand side. 
    5050 * Pattern synonyms are not allowed to be recursive.  Cf. type synonyms.
    51  * The semantics is simply given by expansion of the synonym.
     51 * The semantics is simply expansion of the synonym.
    5252
    53 Pattern synonyms can be exported and imported by mentioning the ''conid'' in the export/import list.  Note that this suffers from the same constructor vs type confusion that already exists in `hiding` list, i.e., given the mention of a ''conid'' you cannot tell if it refers to a constructor or a type.
     53Pattern synonyms can be exported and imported by mentioning the ''conid'' in the export/import list.  Note that this suffers from the same constructor vs type confusion that already exists in a `hiding` list, i.e., given the mention of a ''conid'' you cannot tell if it refers to a constructor or a type.
    5454
    5555You may also give a type signature for a pattern, but as with most other type signatures in Haskell it is optional:
     
    6464
    6565== Pattern only synonyms ==
    66 The simple patterns synonyms are restricted to having a right hand side that is also a valid expression.
    67 The pattern only synonyms can have any pattern on the right hand side, but may only be used in patterns.
     66Simple patterns synonyms are restricted to having a right hand side that is also a valid expression.
     67Pattern only synonyms can have any pattern on the right hand side, but may only be used in patterns.
    6868
    6969`pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `=` ''pat''
    7070
    71 Again, each of the variables on the left hand side must be mentioned exactly once of the right hand side, but the right hand side can mention other variables as well.  These variables will not be bound by using the pattern synonyms.
     71Again, each of the variables on the left hand side must be mentioned exactly once on the right hand side, but now the right hand side can mention other variables as well.  These variables will not be bound when using the pattern synonym.
    7272
    7373Examples:
     
    101101
    102102== Bidirectional pattern synonyms ==
    103 What if you want to use `Plus1` from the earlier example in an expression.
     103What if you want to use `Plus1` from the earlier example in an expression?
    104104It's clearly impossible since its expansion is a pattern that has no meaning as an expression.
    105 Nevertheless, if we want to make what looks like constructors for a type we will often want to use them in both patterns and expressions.
    106 This is the rational for the most complicated synonyms, the bidirectional ones.  They provide two expansions, one for patterns and one for expressions.
     105Nevertheless, if we want to make what looks like a constructor for a type we will often want to use it in both patterns and expressions.
     106This is the rationale for the most complicated synonyms, the bidirectional ones.  They provide two expansions, one for patterns and one for expressions.
    107107
    108108`pattern` ''conid'' ''varid,,1,,'' ... ''varid,,n,,'' `=` ''pat'' `where` ''cfunlhs'' ''rhs''
     
    115115      Plus1 n = n + 1
    116116}}}
    117 The first part as is before and describes the expansion of the synonym in patterns, whereas the second describes the expansion in expressions.
     117The first part as is before and describes the expansion of the synonym in patterns. The second part describes the expansion in expressions.
    118118
    119119{{{