[Git][ghc/ghc][wip/marge_bot_batch_merge_job] doc: Add documentation for -XDoAndIfThenElse
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Thu Jan 23 19:15:43 UTC 2025
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
1c6992fb by Teo Camarasu at 2025-01-23T14:15:38-05:00
doc: Add documentation for -XDoAndIfThenElse
Resolves #18631
Co-authored-by: Richard Eisenberg <rae at cs.brynmawr.edu>
- - - - -
4 changed files:
- docs/users_guide/conf.py
- docs/users_guide/expected-undocumented-flags.txt
- + docs/users_guide/exts/doandifthenelse.rst
- docs/users_guide/exts/syntax.rst
Changes:
=====================================
docs/users_guide/conf.py
=====================================
@@ -36,7 +36,6 @@ nitpick_ignore = [
("c:type", "bool"),
- ("extension", "DoAndIfThenElse"),
("extension", "RelaxedPolyRec"),
]
=====================================
docs/users_guide/expected-undocumented-flags.txt
=====================================
@@ -7,7 +7,6 @@
-XAlternativeLayoutRule
-XAlternativeLayoutRuleTransitional
-XAutoDeriveTypeable
--XDoAndIfThenElse
-XDoRec
-XJavaScriptFFI
-XParallelArrays
=====================================
docs/users_guide/exts/doandifthenelse.rst
=====================================
@@ -0,0 +1,30 @@
+.. _doandifthenelse:
+
+Do And If Then Else
+============
+
+.. extension:: DoAndIfThenElse
+ :shortdesc: Allow semicolons in ``if`` expressions.
+
+ :since: 7.0.1
+
+ :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.
=====================================
docs/users_guide/exts/syntax.rst
=====================================
@@ -20,6 +20,7 @@ Syntax
lambda_case
empty_case
multiway_if
+ doandifthenelse
local_fixity_decls
block_arguments
typed_holes
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c6992fbd5e50a8ffdc90a2d3707d3ae169441bb
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c6992fbd5e50a8ffdc90a2d3707d3ae169441bb
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250123/8abe1ff1/attachment-0001.html>
More information about the ghc-commits
mailing list