1

I am looking to learn functional programming with an am to integrate Boost.phoenix into my project.

What language is most similar so that I can find books that will illustrate functional programming concepts in a way that can be readily applies in that context... Are haskell and ocaml similar?

ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?

eigen_enthused
  • 525
  • 6
  • 17

3 Answers3

4

Phoenix enables functional programming (FP) in C++. Consequently, the language that will be most synergistic is going to be C++.

If you want to learn functional programming on its own terms, languages like Haskell and Scheme may be better choices.

http://www.boost.org/doc/libs/1_51_0/libs/phoenix/doc/html/index.html

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • I am looking to use C++ but I am looking for a good book on approaching problems from a functional perspective - patterns for that idiom - that can be readily applied back to Phoenix, even if the code in the book is for a different but conceptually compatible language. – eigen_enthused Oct 19 '12 at 00:49
  • 3
    If Phoenix is truly functional (which I'm inclined to think it is), the principles it embodies are universal, and any decent functional language and book will suffice. Phoenix's focus is to bring functional programming to C++; in my experience, bolting on such a major feature to an already mature language is bound to create some intricacies that will complicate your learning process, unless you are already proficient at C++ programming. – Robert Harvey Oct 19 '12 at 02:10
  • You are looking for a book that explains the design patterns and idioms of functional programming and the relevant software architecture. I'm not sure there any such books at all. Writing one such book is my current project. :) – winitzki Oct 19 '12 at 08:27
2

I don't have any experience with Phoenix (I've skimmed the docs), but I do have some with C++, OCaml, and Haskell so I may be able to help there.

First off, if you learn functional programming you'll find it doesn't translate prettily to C++ - it ends up messier and more verbose than if done in an actual functional language. Nevertheless, it is still worth learning the techniques as they will give you more tools and a different mindset.

Are haskell and ocaml similar?

They are both influenced by ML so they are quite similiar (well, sorta, see the comments). OCaml is closer to C++ because of it's imperative and OO features, but I recommend you learn Haskell as it is more functional, more mindbending, and has more resources. An interesting thing about ML-like languages that they translate quite nicely to template metaprogramming.

ALternately are there any good functional programming books written in general terms that can be applied to Boost.phoenix?

The docs of Phoenix seem to use fairly standard terms. The one thing which could be confusing is their use of the word 'functor' - in C++ it means function object but in languages like Haskell it is something else.

Here are a few terms that you should look for:

  • lambda / anonymous function
  • first class function
  • function application
  • partial application and currying
  • composition
  • strict/non-strict/lazy evaluation
  • recursion
  • closures

Here are two free books which I recommend reading as they are a great introduction to functional programming:

http://learnyouahaskell.com/chapters (Haskell)

http://mitpress.mit.edu/sicp/full-text/book/book.html (Scheme)

Pubby
  • 51,882
  • 13
  • 139
  • 180
  • 2
    Haskell isn't a SML derivate, they both appeared about a same time and were quite different. – Matvey Aksenov Oct 19 '12 at 07:44
  • 1
    Haskell's "lineage" is rooted in the Turner family of lazy languages SASL, KRC then Miranda. Roughly speaking ML (prior to SML) is contemporary to SASL and KRC, Miranda is contemporary to SML. Haskell came a bit later. – stephen tetley Oct 19 '12 at 14:19
2

I don't know much about Phoenix but I think that Okasaki's Purely Functional Data Structures can give you more or less general look how to write programs in functional style.

Kakadu
  • 2,837
  • 19
  • 29