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

RE: Can a functional language be sequential?



Michael St. Hippolyte wrote:
> I'm still left wondering whether putting expressions in a sequence
> which describes the order of assembly of the resulting values, not
> the order of evaluation, in and of itself disqualifies a lanugage
> from being functional.

Not at all.  A sequence as you defined it ("evaluate all of these; if there
are more than
one, concatenate the values in sequence; return the resulting value") sounds
like a concatenation operator.  Being able to control the ordering of the
resulting value is essential and doesn't violate functionalness at all.

Haskell, which is as functionally pure as languages come, supports
concatenation of e.g. lists or strings via a ++ operator, e.g.:

"ab" ++ "bg" ++ "ef"   ==>  "abbgef"

[1,2] ++ [4,3] ++ [9,6]  ==>  [1,2,4,3,9,6]

The ordering of the results is guaranteed, and in this case is based on
operator precedence.  However, that's just a syntactic sugar issue.

The requirement of being able to assemble values in a specified order is
fundamental: without it, functional programmers would spend a lot of time
rearranging the randomly ordered output of their programs to understand what
the results were!  However, as you observed, this has nothing to do with
order of evaluation.

> Since it does not introduce any side effects (barring fatal
> errors and nontermination), it seems to me it could still
> be considered functional, technically if not stylistically.

It's purely, technically, and stylistically functional.

Regarding order of evaluation, constraining that alone would not make a
language non-functional; but in a purely functional language, I can't think
of a reason that a defined order of evaluation would be needed, so its
presence as a requirement would be suspicious.

Anton