I'm hardly knowledgeable about FunctionalProgramming; I learned SchemeLanguage some 13 years ago and in recent years undertook some superficial forays into LambdaCalculus. Still, I'm continually attracted to FP and constantly on the verge of really learning a FunctionalProgramming language.
On a small scale, I feel comfortable with using idioms and patterns borrowed from FunctionalProgramming in an ObjectOrientedLanguage. I have no grasp at all, though, how FP works in the large. Most of the stuff I have read about SoftwareArchitecture and Design seems to take ObjectOrientedProgramming for granted. Also, there are methods of analysis and design that help find the objects and incrementally get to a well-designed, well-factored system.
Now, I would like to understand how this works when a FunctionalProgramming language is used instead of an ObjectOrientedLanguage. I'm quite sure, that two systems, where one is implemented using an FPL and the other using an OOL will look very different on the inside, even if they behave the same when viewed externally.
Though no expert I've written quite a bit of code in SchemeLanguage and I try to keep to a functional style. I find the two main patterns are the stream and the transform. Almost inevitably data arrives as a stream (though often I accumulate it into a list) and then goes through a bunch of transforms to reach the end result. This is just the standard HigherOrderFunction patterns (map, fold etc.) applied to the whole system. Occasionally there are some parts that have state. I don't have a good name for them yet, but invariably it is where identity is important, rather than value. Here I have to use imperative style though I feel all these cases could be done using LinearTypes like CleanLanguage has. This is all very half-formed but I hope it helps you! Incidentally this is what my Java code ends up looking like as well. -- NoelWelsh
I can imagine how this works for an application that reads input, processes it, and generates output. But I don't think it is suitable for interactive applications or multiuser, multitier applications. -- MichaelSchuerig
Ok, take the robot metaphor. A robot has sensors (inputs) and actuators (outputs). It receives inputs and transforms it into outputs. There can be various priorities and higher priority tasks may prevent a lower priority task from completing (a subsumption architecture, popular in robotics). This is completely functional and describes many server applications, such as web servers. Now slap a GUI on it. The buttons and input boxes become the sensors and the output is whatever is appropriate (say performance statistics for a web server). Still functional. Now add a memory. There is only a single memory, so it's a linear type as I understand them. Still functional. Does that help? -- NoelWelsh
Hm. Somewhat. Still, I only have a very vague idea of how a large functional program works. How to get along without state? How to manage dependencies without interfaces and polymorphism? -- MichaelSchuerig
Most functional languages have module systems that provide similar facilities to interfaces and polymorphism. Typically you define a signature that is a bunch of things a module must provide (like an interface) and multiple modules can implement that interface. For example, you can define a set interface (say, add-item member?) have different implementation implement the interface.
Now, if anyone could give an example of how this looks in practice... -- MS
What sort of example? Actual source code pasted into this window or pointers to other projects? In the latter case, most of the FP systems are written in themselves.
If possible, high-level descriptions of the architecture of various large systems implemented in a FunctionalProgrammingLanguage. Actual source code probably is too specific an only the already initiated will understand it. -- MS
You could look at the write-ups for past years' IcfpProgrammingContest entries. Many of them include both source code and descriptions of the solution and the process of coming up with the solution. You could also compare the approaches taken by the functional vs imperative language entries.
How functional are we talking here? Many "functional" languages support destructive operations, OO-style coding and global state. Lisp, Scheme and OCaml are notable examples. Most languages without some kind of system for global state aren't used as much as those that are, or have come up with interesting ways of simulating it (Monads in the HaskellLanguage). -- DaveFayram