Functional Programming

"Martin v. Löwis" martin at v.loewis.de
Mon Dec 23 08:27:05 EST 2002


beno wrote:
> Does 
> anyone know of good sources of info for programming using the principles 
> of functional programming in Python? Or, to what languages is Haskell 
> similar? Any other advice on the subject equally welcomed!

You could ask Google:

http://www-106.ibm.com/developerworks/linux/library/l-prog.html

I think most examples from your book would translate literally to 
Python. A number of mechanisms that people often associate with 
functional programming are not directly available in Python:

- lazy evaluation (arguments are not evaluated if they don't contribute
   to the result). There is no clean way to emulate it in a language that
   does not have it. In some cases, transforming expressions to
   statements (in particular, if-statements) helps. In some cases,
   generators can be used instead.

- tail recursion: while it is available in most languages, it is often
   not eliminated, but can cause stack overflows. You either need to
   rewrite it into a while-loop, or eliminate it from the algorithm
   altogether (e.g. by using map).

- Currying (creating a function from another function by passing some
   arguments): This is not directly available in Python; you can often
   emulate it with lambda expressions.

http://www-106.ibm.com/developerworks/linux/library/l-prog3.html

   gives nicer-to-write syntax for that.

Regards,
Martin




More information about the Python-list mailing list