Thursday, August 9, 2007

Functional Programming ponders

I first encountered functional programming in an academic course that I took in my undergraduate studies for a B.Sc. in computer and software engineering at the Technion. The course name was Structure and Interpretation of Computer Programs (044261). It is no incident that this name is the name of a very popular and successful book: Structure and Interpretation of Computer Programs (mit press). This book given an introduction to programming using the functional language Scheme. The authors, Abelson and the Sussmans, goal as they put it in the preface to the first edition of their book:

"Our goal is that students who complete this subject should have a good feel for the elements of style and the aesthetics of programming. They should have command of the major techniques for controlling complexity in a large system. They should be capable of reading a 50-page-long program, if it is written in an exemplary style. They should know what not to read, and what they need not understand at any moment. They should feel secure about modifying a program, retaining the spirit and style of the original author."

I truely enjoyed reading this book, enjoyed the course and learned a lot from the assignments given in this course. Since then I wanted many times to be able to re-read the book cover-to-cover, and not just the needed material for the current assignment in the course, enjoy and learn in detail and complete all exercises. I didn't get to do it so far... unfortunately.

The next encounter was reading MDJ's material on closures in Perl, and the material on it in the perldoc and Perl literature. A few years later, MJD released his Higher Order Perl book, which delved into the functional programming aspect of Perl programming in greater detail, and actually suggested a consideration of functional programming approach to some of the problems people solve, and showed and explained how these can be done in Perl. I did get to read this book cover to cover. I did attempt to solve myself the problems raised in this book and got to do it. The process was indeed rewarding. Check out the book review on HOP that I wrote on Amazon.

A few months ago I got to know Zohar Kelrich, who infected me with a need to understand, learn and use Haskell. This actually was after I heard some other Israeli Perl Mongers, such as Yuval Kogman, Yuval Yaari and Gabor Szabo mention Haskell, its potential and its usage in implementing Perl 6. As much as Haskell gets good marks as powerful programming language, I found the available online material on it very hard for me. I still don't consider myself Haskell literate.

So I decided to focus my Functional Programming education efforts on Scheme, get good understanding, then try to apply my knowledge in Perl and then only when I have solid ground dive back into Haskell.

Here are some items from a book order I am going to post later on today:
I intend to find the time and read all these cover to cover, do all exercises and understand scheme enough to be able to:
  1. compare Scheme with Haskell (which should be useful once I understand Scheme in full -- this should be more practical, I think, than comparing Haskell to Perl). I hope that the process will give me enough insight and understanding that will help me progress and advance my understanding in functional programming
  2. Apply schema-like and functional programming practices and ideas into my Perl and C programming.
  3. Hopefully this process will allow me to come up with interesting and useful designs and develop a yet more open mind that will lead me to more good ideas in solving problems at work.
A (too) few ideas (I'm afraid) that I am using from Functional Programming are:
  • Closures
  • Functions as data (including functions as arguments and as return data)
  • Recursion
  • Divide and Conquer
A few ideas (that I know by name to be able to list them...) that I tried to understand but was not able to do it successfully yet are:
  • monads
  • continuations
  • type-systems (I'm not sure that this necessarily applies to functional programming, but I did find this to be key in Haskell)
There are, I'm sure, a lot more ideas in Functional Programming that I don't even know to name, and once I get some more understanding and practice, will, hopefully become accessible to me.

No comments:

Post a Comment