views:

391

answers:

5

I have just started delving into the world of functional programming.

A lot of OOP (Object Oriented Programming) concepts such as inheritance and polymorphism apply to most modern OO languages like C#, Java and VB.NET.

But how about concepts such as Map, Reduce, Tuples and Sets, do they apply to all FP (Functional Programming) languages?

I have just started with F#. But do aforementioned concepts apply to other FP like Haskell, Nemerle, Lisp, etc.?

+5  A: 

You bet. The desirable thing about function programming is that the mathematical concepts you describe are more naturally expressed in an FP.

It's a bit of tough going, but John Backus' Turing Award paper in which he described functional (or "applicative") programming is a good read. The Wikipedia article is good too.

Charlie Martin
@Charlie: That paper looks a bit tough to swallow for me in my current condition. But looks like something I can spend some time on to actually learn. Thanks.
Sung Meister
"That which does not kill me makes me stronger." ;-)
Charlie Martin
@Charlie: I thought that applied only to spicy food.. ;)
Sung Meister
+2  A: 

Yes; higher-order functions, algebraic data types, folds/catamorphisms, etc are common to almost all functional languages (though they sometimes go by slightly different names in each language).

Brian
+2  A: 

Functional tools apply to all programming, not just languages that handle that explicitly. For example, python has map and reduce builtin functions that do exactly what you expect, besides out of order evaluation. you'll need something like the multiprocessing module to get really clever.

Even if the language doesn't provide the exact primitives, most modern languages still make it possible to get the desired effect with a bit more work. This is similar to the way a class-like concept can be coded in pure C.

TokenMacGuy
Sung Meister
it'd be possible with any Turing complete language (pretty much everything but the C preprocessor, including Ook and Brainfuck), no?
Carson Myers
Obviously there is not computational power inferred by functional programming that a turing trap couldn't achieve. The real benefit is the expressive power of the language combined with the feature of efficient implementation of the operators. It is very difficult to get a turing trap language to both perform the action in a way that is efficient and also easy to understand.
TokenMacGuy
A: 

They apply to all languages that contain data types that can be "mapped" and "reduced", i.e maps, arrays/vectors, or lists.

In a "pure lambda calculus" language, where every data structure is defined via function application, you can of course apply functions in parallel (i.e., in a call fn(expr1, expr2), you can evaluate expr1 and expr2 in parallel), but that isn't really what map/reduce is about.

mfx
+1  A: 

If you really want to jump into the deep end and understand why these concepts are not just conventional but, ahem, foundational, check out the paper "Functional programming with bananas, lenses, envelopes and barbed wire".

Chris Conway