diff options
author | Dr. ERDI Gergo <gergo@erdi.hu> | 2014-07-29 11:33:57 +0200 |
---|---|---|
committer | Dr. ERDI Gergo <gergo@erdi.hu> | 2014-07-29 15:44:32 +0200 |
commit | 535b37cbb5a11dd4c9d8260d1d00f4cb993af0e9 (patch) | |
tree | c5cb57c755de46cb6d8a07dc2b1fbf26e7d3493d | |
parent | 3219ed9629a75b3b8b6757ee3ab5a8acc70f6900 (diff) | |
download | haskell-535b37cbb5a11dd4c9d8260d1d00f4cb993af0e9.tar.gz |
Add user documentation for explicitly-bidirectional pattern synonymswip/pattern-synonyms
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 7b49a55dc2..ff7f3eae74 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -987,9 +987,15 @@ Which enables us to rewrite our functions in a much cleaner style: In this case, <literal>Head</literal> <replaceable>x</replaceable> cannot be used in expressions, only patterns, since it wouldn't specify a value for the <replaceable>xs</replaceable> on the -right-hand side. +right-hand side. We can give an explicit inversion of a pattern +synonym using the following syntax: </para> +<programlisting> + pattern Head x <- x:xs where + Head x = [x] +</programlisting> + <para> The syntax and semantics of pattern synonyms are elaborated in the following subsections. @@ -1008,6 +1014,10 @@ bidirectional. The syntax for unidirectional pattern synonyms is: and the syntax for bidirectional pattern synonyms is: <programlisting> pattern Name args = pat +</programlisting> or +<programlisting> + pattern Name args <- pat where + Name args = expr </programlisting> Either prefix or infix syntax can be used. @@ -1020,11 +1030,12 @@ bidirectional. The syntax for unidirectional pattern synonyms is: </para> <para> The variables in the left-hand side of the definition are bound by - the pattern on the right-hand side. For bidirectional pattern - synonyms, all the variables of the right-hand side must also occur - on the left-hand side; also, wildcard patterns and view patterns are - not allowed. For unidirectional pattern synonyms, there is no - restriction on the right-hand side pattern. + the pattern on the right-hand side. For implicitly bidirectional + pattern synonyms, all the variables of the right-hand side must also + occur on the left-hand side; also, wildcard patterns and view + patterns are not allowed. For unidirectional and + explicitly-bidirectional pattern synonyms, there is no restriction + on the right-hand side pattern. </para> <para> |