Skip to content
Snippets Groups Projects
Commit eec047d8 authored by Teo Camarasu's avatar Teo Camarasu
Browse files

doc: Add documentation for -XDoAndIfThenElse


Resolves #18631

Co-authored-by: default avatarRichard Eisenberg <rae@cs.brynmawr.edu>
parent 09ee3247
No related branches found
No related tags found
No related merge requests found
Pipeline #105913 passed
......@@ -36,7 +36,6 @@ nitpick_ignore = [
("c:type", "bool"),
("extension", "DoAndIfThenElse"),
("extension", "RelaxedPolyRec"),
]
......
......@@ -7,7 +7,6 @@
-XAlternativeLayoutRule
-XAlternativeLayoutRuleTransitional
-XAutoDeriveTypeable
-XDoAndIfThenElse
-XDoRec
-XJavaScriptFFI
-XParallelArrays
......
.. _doandifthenelse:
Do And If Then Else
============
.. extension:: DoAndIfThenElse
:shortdesc: Allow semicolons in ``if`` expressions.
:status: Included in :extension:`Haskell2010`
Allow semicolons in ``if`` expressions.
Normally, a conditional is written like this: ``if cond then expr1 else expr2``. With the extension
:extension:`DoAndIfThenElse`, semicolons are allowed before the ``then`` and also before the ``else``, allowing
``if cond; then expr1; else expr2``. (You can also include either semicolon on its own.)
Allowing semicolons in the middle of a conditional is useful in connection with layout-controlled
blocks, like ``do``\ -blocks. This is because GHC invisibly inserts a semicolon between each line of a
layout-controlled block. Accordingly, with :extension:`DoAndIfThenElse`, we can write code like this ::
f mb x y = do
b <- mb
if b
then x
else y
Without :extension:`DoAndIfThenElse`, the ``then`` and ``else`` lines would have to be indented with respect
to the rest of the lines in the ``do``\ -block.
......@@ -20,6 +20,7 @@ Syntax
lambda_case
empty_case
multiway_if
doandifthenelse
local_fixity_decls
block_arguments
typed_holes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment