Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add section about if-then-else clauses

  • Loading branch information...
commit 6999aa020c776fd265aa269bd951dcc666bb0ea7 1 parent 74d065c
@jaspervdj jaspervdj authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 haskell-style.md
View
38 haskell-style.md
@@ -152,6 +152,44 @@ module Data.Set
) where
```
+### If-then-else clauses
+
+Generally, guards and pattern matches should be preferred over if-then-else
+clauses, where possible. Short cases should usually be put on a single line
+(when line length allows it).
+
+Otherwise, you should be consistent with the 4-spaces indent rule, and the
+`then` and the `else` keyword should be aligned. Examples:
+
+```haskell
+foo = do
+ someCode
+ if condition
+ then someMoreCode
+ else someAlternativeCode
+```
+
+```haskell
+foo = bar $ \qux -> if predicate qux
+ then doSomethingSilly
+ else someOtherCode
+```
+
+The same rule applies to nested do blocks:
+
+```haskell
+foo = do
+ instruction <- decodeInstruction
+ skip <- load Memory.skip
+ if skip == 0x0000
+ then do
+ execute instruction
+ addCycles $ instructionCycles instruction
+ else do
+ store Memory.skip 0x0000
+ addCycles 1
+```
+
Imports
-------
Please sign in to comment.
Something went wrong with that request. Please try again.