wiki:NondecreasingIndentation

Version 6 (modified by igloo, 5 years ago) (diff)

--

Nondecreasing Indentation

Ticket: #53

Compiler support

GHC full (-XNondecreasingIndentation; enabled by default)
nhc98 unknown
Hugs unknown
UHC unknown
JHC unknown
LHC unknown

Brief Explanation

Layout, as described in s9.3 of the Haskell 98 Report, has a rule

L ({n}:ts) (m:ms)        =       { : (L ts (n:m:ms))     if n > m

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:

foo = do
        ...
        if cond then return () else do
        ...
        ...

and a style often used with the ForeignFunctionInterface:

foo = do
        alloca $ \foo -> do
        writeStuff foo
        alloca $ \bar -> do
        writeStuff bar
        alloca $ \baz -> do
        ....

but not

g x = case x of
        Just y -> case y of
        Just z -> z

Doing the same thing after let or where would invalidate legal Haskell 98 programs, e.g.

class C a where

f x = x

References

Pros

  • Just a minor adjustment

Cons

  • If symbols not handled uniformly, adds a special case in an already-obscure part of the language