[commit: ghc] master: docs for new layout behaviour with MultiWayIf (#7783) (d2013e8)

git at git.haskell.org git
Tue Oct 8 19:23:45 UTC 2013


Repository : ssh://git at git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d2013e85976cccde6c915211f8bcc26f2dc93e33/ghc

>---------------------------------------------------------------

commit d2013e85976cccde6c915211f8bcc26f2dc93e33
Author: Simon Marlow <marlowsd at gmail.com>
Date:   Tue Oct 8 19:29:21 2013 +0100

    docs for new layout behaviour with MultiWayIf (#7783)


>---------------------------------------------------------------

d2013e85976cccde6c915211f8bcc26f2dc93e33
 docs/users_guide/glasgow_exts.xml |   30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 92305f2..2a6c818 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -1770,7 +1770,35 @@ which is roughly equivalent to
     ...
     _ | guardN -> exprN
 </programlisting>
-except that multi-way if-expressions do not alter the layout.
+</para>
+
+<para>Multi-way if expressions introduce a new layout context.  So the
+example above is equivalent to:
+<programlisting>
+  if { | guard1 -> expr1
+     ; | ...
+     ; | guardN -> exprN
+     }
+</programlisting>
+The following behaves as expected:
+<programlisting>
+  if | guard1 -> if | guard2 -> expr2
+                    | guard3 -> expr3
+     | guard4 -> expr4
+</programlisting>
+because layout translates it as
+<programlisting>
+  if { | guard1 -> if { | guard2 -> expr2
+                      ; | guard3 -> expr3
+                      }
+     ; | guard4 -> expr4
+     }
+</programlisting>
+Layout with multi-way if works in the same way as other layout
+contexts, except that the semi-colons between guards in a multi-way if
+are optional.  So it is not necessary to line up all the guards at the
+same column; this is consistent with the way guards work in function
+definitions and case expressions.
 </para>
 </sect2>
 




More information about the ghc-commits mailing list