[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can a functional language be sequential?



On 2003.06.01 17:09 James McCartney wrote:
> 
> If your functions have no side effects or mutable variables, then the order 
> that independant functions execute is irrelevant. A function's output 
> depends only on its inputs, not what other functions have run (unless one of 
> those functions is an input). So the question is why do you order your 
> functions if it doesn't matter? A functional language's interpreter is free 
> to reorder the evaluations. The number of possible evaluation orders is the 
> number of permutations of the topological sort of the graph. The result 
> should be the same in all cases.

The order matters not in terms of evaluation but in terms of output.  Think of 
the list of functions as an implicit string concatenation expression -- you 
can evaluate the items in the list in any order you want, as long as the 
results are assembled in order.  For example, a Bento interpreter could 
conceivably start with the last item, then work backwards, prepending the 
result of each evaluation to the string-in-progress.

(I should note a big caveat, as mentioned before: Bento constructions may 
include calls to external methods, e.g. database queries.  In such cases, 
obviously, order of evaluation matters.)

Michael

-----------------------------
Michael St. Hippolyte
http://www.bentodev.org