| > |   f x = case x of
| > |         (a,b) -> case a of
| > |         (c,d) -> case b of
| > |         (e,f) -> [c,d,e,f]
| > 
| > You can't be serious!  This is a great example of mis-using layout to
| > baffle and bemuse.
| 
| I belive he is as it is very similar to
| 
|  {- code -} >>= \(a,b) ->
|  {- code -} >>= \(c,d) ->
|  {- code -} >>= \(e,f) ->  
|  return [c,d,e,f]

No, this is very different.  In a case block, the reader expects a
vertically aligned sequence of patterns, and interprets these as the
possible matches for the initial expression.  The first example
violates this expectation.  In the second example, of cascaded lambda
expressions, the reader has no such expectation - there is no
introductory syntax (case e of...), and each line begins not with a
pattern but with a function application (or if, or case, ...).

|     mcompare x y = 
|              do i <- x ==~ y 
|                 if i then return EQ else do 
|                 i <- x <=~ y 
|                 if i then return LT else do
|                 return GT
| with strictly increasing indentation iut would have to be something like.
|     mcompare x y = 
|              do i <- x ==~ y 
|                 if i then return EQ else do 
|                   i <- x <=~ y 
|                   if i then return LT else do
|                     return GT
| which is a bit uglier.

To be honest, I consider the first of these variants to be an ugly and
confusing misuse of layout, and the second to be clear (if not the most
beautiful way to code it).  The first seems to be trying to simulate a
C-style `return', which is in reality not at all like the true monadic
`return'.  I had to read it several times to understand what was
intended.  More than ugly, I think it is dangerous, because of the
possibility of confusing beginners who are new to both monads and
layout.  Try this variation on the same theme:

      mcompare x y = 
               do i <- x ==~ y 
                  if i then return EQ else do i <- x <=~ y 
                  if i then return LT else do return GT

This code now has a very serious bug!  If you use layout properly, as
with strictly increasing indentation, this confusion is much less
likely to arise.

It seems I am now arguing for, rather than against, the Haskell'98 rule.
Such is life.

Regards,
    Malcolm

P.S. I think this is even clearer:
      mcompare x y = 
               do i <- x ==~ y 
                  if i then return EQ
                    else do i <- x <=~ y 
                            return (if i then LT else GT)
Now if only the layout rules would allow the `else' to align
vertically with the `if'!



Reply via email to