[OT] functional programming resources ?

bearophile bearophileHUGS at lycos.com
Fri Apr 27 15:38:43 PDT 2012


Mariusz Gliwiński:

> could You recommend me some books / materials explaining 
> different concepts in functional programming from *practical 
> point of view*?
> Most preferably not requiring me to understand Haskell or other 
> classical functional language.

It's not easy to answer this question. Maybe it's better to ask
such question in a functional-related newsgroup.

Despite at the base of functional programming there is extremely
simple stuff (lambda calculus) the efficient programming in
modern real functional languages asks for the knowledge of many
ideas and idioms, that requires a certain amount time and energy
to be learnt. And if you are used to OOP/procedural Programming
you will need to bend&twist your brain a bit, and to learn to
compose lots of small functions in your head. So there is no
quick way.

To learn some parts of programming you need to practice, and to
this well it's probably useful to write such code in a language
that speaks functional style natively. So I suggest you to do a
bit of practice in a mostly functional language.

Functional languages are classified as dynamically/statically
typed (Racket Scheme, Clojure, Python are mostly dynamic, OcaML
is mostly static), and lazy/eager (Haskell is lazy, SML is mostly
eager). So you have to decide what style you prefer. Python,
Racket, Haskell are good to learn some functional programming.
Python is only partially functional, and Racket is dynamically
typed and it's a cousin of Lisp. If you want to learn just a bit
of functional programming then Python may be enough. If you are
more serious Haskell is more fit. Scheme is good if you also want
to know more about Lisp-like languages.

If you want to know just a bit of classic functional programming,
then probably simple books like "The little schemer" or "The
little MLer" are OK. There is also SICP (free book:
http://mitpress.mit.edu/sicp/full-text/book/book.html ). But they
don't teach you the newer idioms/ideas, and only "The little
MLer" stresses the idea of types a bit.

"Real world Haskell" (free book:
http://book.realworldhaskell.org/read/ ) is nice to introduce a
bit more real-world functional programming.

I suggest to install the Haskell package, and start to use it,
following some tutorials. You will learn the basic syntax/ideas
quickly, and you will train yourself with higher order functions,
recursivity, typeclasses, algebraic datatyepes, lazy lists,
currying, and so on. Then you will want to learn about monads,
lazyness, avoiding memory leaks, the lambda calculus, zippers,
efficient functional data structures, arrows, and the more
complex functional zoo. You will probably need few years.


> I'd like to try it with D.

There is no "Functional Programming in D" book written yet :-) So
you have to do on your own.


> I'm using more functional style overtime, but i'm afraid to 
> rely on compiler optimizations so highly.

Currently the D front-end doesn't have functional-specific
optimizations (example: if you call filter(map()) using pure
functions, it doesn't swap the two in map(filter())). I presume
future D compilers will want to add some of such optimizations if
D code will contain significant amounts of functional idioms.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list