summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-01-04 10:27:38 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2013-01-04 10:27:38 +0000
commit3671e674757c8f82ec1f0ea9b7c1ed56340b55bc (patch)
tree9c875d12dc2817df632c4f801278bfdfda4c8b93 /docs
parent28d9a03253e8fd613667526a170b684f2017d299 (diff)
downloadhaskell-3671e674757c8f82ec1f0ea9b7c1ed56340b55bc.tar.gz
Allow empty case expressions (and lambda-case) with -XEmptyCase
The main changes are: * Parser accepts empty case alternatives * Renamer checks that -XEmptyCase is on in that case * (Typechecker is pretty much unchanged.) * Desugarer desugars empty case alternatives, esp: - Match.matchWrapper and Match.match now accept empty eqns - New function matchEmpty deals with the empty case - See Note [Empty case alternatives] in Match This patch contains most of the work, but it's a bit mixed up with a refactoring of MatchGroup that I did at the same time (next commit).
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/glasgow_exts.xml38
1 files changed, 38 insertions, 0 deletions
diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml
index 93279aaa13..98c43c2135 100644
--- a/docs/users_guide/glasgow_exts.xml
+++ b/docs/users_guide/glasgow_exts.xml
@@ -1666,6 +1666,44 @@ Note that <literal>\case</literal> starts a layout, so you can write
</para>
</sect2>
+<sect2 id="empty-case">
+<title>Empty case alternatives</title>
+<para>
+The <option>-XEmptyCase</option> flag enables
+case expressions, or lambda-case expressions, that have no alternatives,
+thus:
+<programlisting>
+ case e of { } -- No alternatives
+or
+ \case { } -- -XLambdaCase is also required
+</programlisting>
+This can be useful when you know that the expression being scrutinised
+has no non-bottom values. For example:
+<programlisting>
+ data Void
+ f :: Void -> Int
+ f x = case x of { }
+</programlisting>
+With dependently-typed features it is more useful
+(see <ulink url="http://hackage.haskell.org/trac/ghc/ticket/2431">Trac</ulink>).
+For example, consider these two candidate definitions of <literal>absurd</literal>:
+<programlisting>
+data a :==: b where
+ Refl :: a :==: a
+
+absurd :: True :~: False -> a
+absurd x = error "absurd" -- (A)
+absurd x = case x of {} -- (B)
+</programlisting>
+We much prefer (B). Why? Because GHC can figure out that <literal>(True :~: False)</literal>
+is an empty type. So (B) has no partiality and GHC should be able to compile with
+<option>-fwarn-incomplete-patterns</option>. (Though the pattern match checking is not
+yet clever enough to do that.
+On the other hand (A) looks dangerous, and GHC doesn't check to make
+sure that, in fact, the function can never get called.
+</para>
+</sect2>
+
<sect2 id="multi-way-if">
<title>Multi-way if-expressions</title>
<para>