Changes between Version 2 and Version 3 of NondecreasingIndentation


Ignore:
Timestamp:
Nov 29, 2005 10:14:37 AM (10 years ago)
Author:
ross@…
Comment:

consolidate, and add notes on uniformity

Legend:

Unmodified
Added
Removed
Modified
  • NondecreasingIndentation

    v2 v3  
    55
    66== Brief Explanation ==
    7 Ross says: I think NondecreasingIndentation refers to changing > in the H98 (s9.3) rule
     7Layout, as described in [http://www.haskell.org/onlinereport/syntax-iso.html#sect9.3 s9.3 of the Haskell 98 Report], has a rule
    88{{{
    9         L ({n}:ts) (m:ms)        =       { : (L ts (n:m:ms))     if n > m
     9L ({n}:ts) (m:ms)        =       { : (L ts (n:m:ms))     if n > m
    1010}}}
    11 to >=.  GHC and Hugs do this if the previous token was "do", i.e. they
    12 accept
     11GHC and Hugs change the above > to >= if the previous token was `do`, but not if it was `let`, `where` or `of`.
     12This allows uses like short-circuiting returns ''a la'' imperative languages:
    1313{{{
    14         f = do
    15                 x <- readLn
    16                 withFoo $ \ y -> do
    17                 z <- readLn
    18                 print (x+y+z)
    19 }}}
    20 but not
    21 {{{
    22         g x = case x of
    23                 Just y -> case y of
    24                 Just z -> z
    25 }}}
    26 
    27 
    28 Common uses of this extension are
    29 {{{
    30 -- short-circuiting returns a la imperative languages
    31 
    3214foo = do
    3315        ...
     
    3517        ...
    3618        ...
    37 
    38 -- when using the FFI one commonly has a lot of nested alloca-like routines
    39 
     19}}}
     20and a style often used with the ForeignFunctionInterface:
     21{{{
    4022foo = do
    4123        alloca $ \foo -> do
     24        writeStuff foo
    4225        alloca $ \bar -> do
     26        writeStuff bar
    4327        alloca $ \baz -> do
    4428        ....
     29}}}
     30but not
     31{{{
     32g x = case x of
     33        Just y -> case y of
     34        Just z -> z
     35}}}
     36Doing the same thing after `let` or `where` would invalidate legal Haskell 98 programs, e.g.
     37{{{
     38class C a where
    4539
    46 
     40f x = x
    4741}}}
    4842
     
    5448 * Just a minor adjustment
    5549
    56 
    5750== Cons ==
    58  * Con
    59  * Con
     51 * If symbols not handled uniformly, adds a special case in an already-obscure part of the language