www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [OT] functional programming resources ?

reply =?UTF-8?B?TWFyaXVzeiBHbGl3acWEc2tp?= <alienballance gmail.com> writes:
Hello,
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.

I'd like to try it with D.

I'm using more functional style overtime, but i'm afraid to rely on 
compiler optimizations so highly.
Anyways, i don't feel like i could write big part of my code pure && 
functional yet, so i'd like to learn about it at least a bit more.

Thanks,
Mariusz Gliwiński
Apr 27 2012
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
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
Apr 27 2012
prev sibling parent "SomeDude" <lovelydear mailmetrash.com> writes:
On Friday, 27 April 2012 at 20:52:28 UTC, Mariusz Gliwiński 
wrote:
 Hello,
 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.

 I'd like to try it with D.

 I'm using more functional style overtime, but i'm afraid to 
 rely on compiler optimizations so highly.
 Anyways, i don't feel like i could write big part of my code 
 pure && functional yet, so i'd like to learn about it at least 
 a bit more.

 Thanks,
 Mariusz Gliwiński

It has nothing to do with D, (Scheme instead, don't worry, you learn the language along), but Abelson and Süssman's "Structure and Interpretation of Computer Programs" (SICP) probably is one of the best computer science books ever written. And an eye opener. http://mitpress.mit.edu/sicp/ http://deptinfo.unice.fr/~roy/sicp.pdf It's free online, and there is a a free online course in videos. http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/ And you can use any scheme interpreter to try the examples (Racket is good for instance).
Apr 28 2012