15 ms·
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 beginnin
by dan00 15y ago
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 -> ..
- hollerith 15y agoWe 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.)
- eru 15y agoI 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/thread/6f80e46ae3695979/7cb2c5d36c36c7f4 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.
- hollerith 15y agoAgree about case lambda (and consequently that I could have chosen a better example).