Monday, September 8, 2008

Book Samples in F#

I'm fairly new to functional programming but I am on my second reading of a couple of great titles: The Little MLer and Purely Functional Data Structures.

Both of these books contain code samples in Standard ML (SML) (the latter contains a Haskell appendix). Readers with a background in functional languages would have no problem translating from SML to OCaml and F# but for newcomers this can be a very complicated endeavor and it greatly detracts from the reading.

When I first read these books I failed to find any code examples in F# and I even struggled to find OCaml samples based on the books. In order to encourage newcomers to F# to take up a study of functional programming, I have started a project on Google Code to address this need. The project will host relative ports of code samples from various books.

I do not intend for the ports to be literal translations. There are, for instance, constructs in SML that simply aren't available in F#. But the samples should convey the spirit of the book even if they use different means to achieve that end.

If you have samples or suggestions, corrections, or improvements for the samples, please get in touch!


grahamsw said...

Great idea. I've found that making the translations is very helpful in both understanding the underlying functional programming (I'm still not convinced that the inside of my head is big enough for FP, but it's a blast trying) and for solidifying my grasp of F#'s syntax. (F# has way too much syntax...)

I got into FP via Lisp, and to some extent Haskell, so I'm attracted to something more ML-like to help me grok the OCaML side of things, but I'm keen to avoid detours, since F# is plenty big enough to keep me busy. Do you recommend the little MLer?

Ray Vernagus said...

Thanks for the comments! The Little MLer is a great book if you want to learn the basics about Union types, tuples, and function types. Of course, if you haven't read any of "The Little ___" series, you would do well to read the book for that experience alone. It's written in a very idiosyncratic way. :)

I'd like to learn of some more introductory books about FP. I have a couple of Haskell titles to digest after the two that I mentioned in my post.

grahamsw said...

Thanks, I'll add it to the never ending queue...

In the meantime - I'm trying to work my way through Programming Collective Intelligence and have been thinking about translating the code in that from Python to F#. I'd love to add that to the Google code project.

The extra motivation, and any suggestions, corrections or improvements, alternatives would be very helpful. As a bonus some of the code in there looks useful.

Ray Vernagus said...

Hey, that's great! As you complete your port you could send a patch and I'll add it to the project.

Do be aware that there may be copyright issues involved. I have spoken to the publishers for the two books that I have included in the project thus far and I received the OK to go ahead. I don't envision any problems with future books since we're recreating the examples in a different language but it's best to be safe.

Alexy said...

Greetings Ray -- hope you know that Markus Mottl implemented almost all of the PFDS in OCaml: