... | ... | @@ -12,58 +12,58 @@ See [ExtensionDescriptionHowto](extension-description-howto) for information on |
|
|
|
|
|
|
|
|
|
|
|
Ross says: I think [NondecreasingIndentation](nondecreasing-indentation) refers to changing \> in the H98 (s9.3) rule
|
|
|
Layout, as described in [ s9.3 of the Haskell 98 Report](http://www.haskell.org/onlinereport/syntax-iso.html#sect9.3), has a rule
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
L ({n}:ts) (m:ms) = { : (L ts (n:m:ms)) if n > m
|
|
|
L ({n}:ts) (m:ms) = { : (L ts (n:m:ms)) if n > m
|
|
|
```
|
|
|
|
|
|
|
|
|
to ≥. GHC and Hugs do this if the previous token was "do", i.e. they
|
|
|
accept
|
|
|
GHC and Hugs change the above \> to ≥ if the previous token was `do`, but not if it was `let`, `where` or `of`.
|
|
|
This allows uses like short-circuiting returns *a la* imperative languages:
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
f = do
|
|
|
x <- readLn
|
|
|
withFoo $ \ y -> do
|
|
|
z <- readLn
|
|
|
print (x+y+z)
|
|
|
foo = do
|
|
|
...
|
|
|
if cond then return () else do
|
|
|
...
|
|
|
...
|
|
|
```
|
|
|
|
|
|
|
|
|
but not
|
|
|
and a style often used with the [ForeignFunctionInterface](foreign-function-interface):
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
g x = case x of
|
|
|
Just y -> case y of
|
|
|
Just z -> z
|
|
|
foo = do
|
|
|
alloca $ \foo -> do
|
|
|
writeStuff foo
|
|
|
alloca $ \bar -> do
|
|
|
writeStuff bar
|
|
|
alloca $ \baz -> do
|
|
|
....
|
|
|
```
|
|
|
|
|
|
|
|
|
Common uses of this extension are
|
|
|
but not
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
-- short-circuiting returns a la imperative languages
|
|
|
g x = case x of
|
|
|
Just y -> case y of
|
|
|
Just z -> z
|
|
|
```
|
|
|
|
|
|
foo = do
|
|
|
...
|
|
|
if cond then return () else do
|
|
|
...
|
|
|
...
|
|
|
|
|
|
-- when using the FFI one commonly has a lot of nested alloca-like routines
|
|
|
Doing the same thing after `let` or `where` would invalidate legal Haskell 98 programs, e.g.
|
|
|
|
|
|
foo = do
|
|
|
alloca $ \foo -> do
|
|
|
alloca $ \bar -> do
|
|
|
alloca $ \baz -> do
|
|
|
....
|
|
|
|
|
|
```wiki
|
|
|
class C a where
|
|
|
|
|
|
f x = x
|
|
|
```
|
|
|
|
|
|
## References
|
... | ... | @@ -77,5 +77,4 @@ foo = do |
|
|
## Cons
|
|
|
|
|
|
|
|
|
- Con
|
|
|
- Con |
|
|
- If symbols not handled uniformly, adds a special case in an already-obscure part of the language |