Version 4 (modified by nhn@…, 11 years ago) (diff)

Added link to the somewhat related issue DoAndIfThenElse

Nondecreasing Indentation

See ExtensionDescriptionHowto for information on how to write these extension descriptions. Please add any new extensions to the list of HaskellExtensions.

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



  • Just a minor adjustment


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