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: [Camllist] Re: Parameter evaluation order 
On Aug 24, 2005, at 03:24, Haoyang Wang wrote: >> Suppose you want to evaluate a curried function call in lefttoright >> 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_ lefttoright > (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 lefttoright order, since you evaluate e0 after the others. In order to stay consistent, you have to evaluate them in righttoleft 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 multiargument function application. Evaluating f last forces you to evaluate the arguments in righttoleft order in expressions like the above.  Damien