From: Christophe Grandsire Date: 2005-10-04T17:08:54+09:00 Subject: Re: Functional Programming? (was Re: Lazy evaluaton) Selon Edward Faulkner : > > Indeed, functional programming is almost the *opposite* of procedural. > In a procedural program, most lines are executed for their side > effects. In a functional program, most lines are executed for their > value. > Incidently, since functions in functional languages (pure ones at least) have no side-effects, order of execution doesn't matter anymore. This also means that there is no such thing as looping anymore. Instead, for looping purposes functional languages use recursion exclusively. It isn't a problem as recursion is more powerful than looping (it is actually mathematically proven that loops are equivalent to a specific kind of recursion called tail recursion). > The key idea in functional programming is that the functions you > define are functions in the mathematical sense. If you call one twice > with the same arguments, you'll always get the same answer each time. > They have no internal state and no side effects. > Indeed, if you look at a program written in Haskell for instance, it really looks like a sort of mathematical notation reduced to fit ASCII :) . > In practice most programs need non-functional parts too, but you can > keep those isolated. The most important case is IO. I personally like the Haskell solution very much (although it is theoretically complicated), because it is still provably purely functional, isolating IO side-effects in objects rather than functions. > > By keeping your code functional, you make it easier to test and debug. > It's inherently thread safe, and optimizations like lazy evaluation > and memoization can be introduced transparently by the > compiler/interpreter. > The only problem is that functional programming is so far removed from the usual idea of "giving instructions for the computer to execute" that most people can't seem to grok it. The functional programming metaphor looks to me more like "giving rules to the computer and problems to be solved with them". Some people may be interested in this: http://raa.ruby-lang.org/project/rtype/ . This is a Ruby interpreter written in Haskell. -- Christophe. http://rainbow.conlang.free.fr It takes a straight mind to create a twisted conlang.