
On Wed, Jan 31, 2007 at 09:43:36 -0500, Mark T.B. Carroll wrote:
Magnus Therning
writes: (snip) Sequential thinking would be related to procedural programming, that is ordering of statements are important but there's no state. Functional programming is declarative, no order and no state. So, to be strict I'd say that sequential form _is_ non-functional. At least if FOLDOC is correct and I read and understood things properly. (snip)
You've completely lost me here. Order is /very/ important in functional programming. Consider function composition:
Prelude> ((+1) . (*2)) 5 11 Prelude> ((*2) . (+1)) 5 12
There we have sequencing, and the computation has intermediate state. There's nothing non-functional about the above.
What you have written above are two mathematical expressions: 2 * 5 + 1 (1 + 5) * 2 Now, correct me if I'm wrong, but you see a "natural" ordering in your haskell expressions, right? However, I don't think there's any pre-defined ordering of the _calculations_ the computer performs in your _equations_ above. In the first one, there isn't much freedom at all due to mathematical rules, however in the second one we have a few choices: - distribute *2 over the parenthesis - calculate the left product, calculate the right, sum it up - calculate the right product, calculate the left, sum it up - compute the sum in the parenthesis, multiply the two factors No matter which is chosen we end up with the same result. So, in the end we don't care about the sequence. However the compiler/interpreter has to choose a sequence in order to arrive at a result, since that's how today's computers work. (Choosing well can be seen as optimisation :-) I know the example here is a bit contrived, but I didn't want to move away from your example. In short, AFAIU: declarative programming: I don't care how you do it, just get it done! sequential programming: You'd better do things in this order! imperative programming: You should do it exactly like this! Oh, if I've fundamentally misunderstood things then I'd love to hear it :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus.therning@gmail.com http://therning.org/magnus