[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: expressions vs. statements
Here is another reason for statement/expression dichotomy (related to the
return issue):
Statements express evaluation order in a more readable manner than
expressions. Therefore you want statements if most of your functions have
side-effects, and you want expressions if most of your functions take an
argument and return a value and you are more indifferent to evaluation
order.
The designers of Haskell recognized this when they gave Monads a separate
syntax from the rest of the language. In an expression like this:
result= h (g (f x))
Functions are evaluated in the opposite order from how they appear. In
contrast, monad syntax (used for IO and sideeffects), looks like this:
result= f x >>= g >>= h
or like this:
result = do
f x
g
h
return
(My haskell is somewhat rusty, so someone here can correct me)
Functions appear in the order they are executed.
The general point:
Statements expres evaluation order in a more readable manner than
expressions.
-Alex-
___________________________________________________________________
S. Alexander Jacobson i2x Media
1-917-783-0889 voice 1-603-288-1280 fax