[Haskell-cafe] let vs. where

Ryan Ingram ryani.spam at gmail.com
Tue Nov 13 16:24:47 EST 2007


I tend to prefer where, but I think that guards & function declarations are
more readable than giant if-thens and case constructs.

"where" can scope over multiple guards, and guards can access things
declared in a "where" clause, both of which are important features:

f xs | len > 2   = y
     | len == 1  = 0
     | otherwise = -y
  where
     len = length xs
     y = ...
compare to

f xs =
    let len = length xs
        y = ...
    in if len > 2 then y
           else if len == 1 then 0
               else -y

The indenting hides the structure of the second function.

   -- ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071113/ccd83fe5/attachment-0001.htm


More information about the Haskell-Cafe mailing list