Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    foo x y = x >>= \a -> case a of
        Leaf -> ..
        Branch aleft aright -> ..
Hanging lambdas yes, but I don't see the advantage of putting the beginning of the case into the same line.

    foo x y = x >>= \a ->
        case a of
             Leaf                -> ..
             Branch aleft aright -> ..
But the example is a bit contrived, because you could write it this way:

    foo x y = do
        a <- x
        case a of
             Leaf                -> ..
             Branch aleft aright -> ..


We must have different goals for our choice of indentation style: my goal is to minimize lines of code while preserving readability.

(Not lining things up as in

  (f xxx
    yyy)
initially detracts from readability, but in my experience with the new style, readability goes back up to very close to where it was as I get used to the new style.)


I actually like the first one best, and would prefer a case-lambda even more. Once it becomes available we can write

  foo x y = x >>= \case
    Leaf -> ..
    Branch l r -> ..
modulo whatever syntax gets chosen. That would save an unnecessary temporary variable. (See https://groups.google.com/group/haskell-cafe/browse_thread/t...)

Temporary variables clutter up the name space. While reading code you have to look for shadowing, or whether that variable is ever used again.


Agree about case lambda (and consequently that I could have chosen a better example).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: