Browse thread
Parameter evaluation order
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Doligez <damien.doligez@i...> |
| Subject: | Re: [Caml-list] Re: Parameter evaluation order |
On Aug 24, 2005, at 03:24, Hao-yang Wang wrote: >> Suppose you want to evaluate a curried function call in left-to-right >> order: >> f e1 e2 e3 e4 >> >> You must evaluate f first, then e1. Then you must apply f to e1, >> giving >> a new function g1. Then you must evalue e2, then apply f1 to e2, >> giving >> f2, etc. >> >> > > It seems to me that as long as evaluate f the last, we are ok. > Yes. > We can specify the evaluation order of the _parameters_ left-to-right > (i.e., e1 then e2, e3, e4, and finally f), without running into the > efficiency problem. > No, that is a contradiction. f is an arbitrary expression of the language, for example (g e0), so the code above might well be in fact: g e0 e1 e2 e3 e4 Now, if you evaluate f last, you are obviously not evaluating the arguments in left-to-right order, since you evaluate e0 after the others. In order to stay consistent, you have to evaluate them in right-to-left order. In fact, when all your functions are curried there are only two possible choices: evaluate the function first, or the argument first. There is no such thing as a multi-argument function application. Evaluating f last forces you to evaluate the arguments in right-to-left order in expressions like the above. -- Damien