On Nov 13, 2007 10:56 AM, John Lato <[EMAIL PROTECTED]> wrote:
> I know there are several important differences between let-expressions
> and where-clauses regarding scoping and the restriction of "where" to
> a top-level definition.  However, frequently I write code in which

One place I find it useful is when there is  a common computed value
that is used throughout a function definition. For example, imagine
some function that uses the length of a list passed in:

  someFunction ls a b c = ... (length ls)
     where
       someAuxFunction x y = ... length ls ..
       someOtherFunction x y = ... length ls ...

a where clause can capture that calculation, make sure it's only done
once, and shared throughout the function definition:

  someFunction ls a b c = ... listLen ...
     where
       listLen = length ls
       someAuxFunction x y = ... listLen ...
       someOtherFunction x y = ... listLen ...

Notice a let clause wouldn't do it above, because "length ls" is
called inside other functions defined in the where clause. Of course
everything could be moved to a "let" clause in the function body. At
that point I think it's purely stylistic.

Justin
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to