To all of you Functional Programming gurus out there

What’s some examples of programming problems that would be good for learning functional programming?  I’m looking for categories of problems that are better addressed with functional programming instead of OO.


I’m thinking about using F# as part of StoryTeller to write a syntax checker for Fit tests against the Fixture classes to provide something like compile time checks for Fit test syntax.


 


Thanks in advance.

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.xhovemont.be david.brabant@cybernet.be

    The map/reduce programming model is a cannonical application of functional programming.

    See this:
    http://labs.google.com/papers/mapreduce-osdi04.pdf

    and this:
    http://www.joelonsoftware.com/items/2006/08/01.html

    to grasp why functional programming is waaayyy cool.


    David

  • Greg

    depth first searches are good problems (any tree based problem in general, including n-linked which is your typical domain)

    Can I recommend a book? I promise it will make your imperative code better if nothing else. “Purely Functional Data Structures”

    Cheers,

    Greg

  • http://chrisdonnan.com/blog chris donnan

    I have been reading “Programming Erlang”. It may be a good place for you to check out functional programming. I also have been looking to use a functional language and use it properly – the paradigms ARE different and i also do not want to just try to use the OO-isms in that context – but REALLY to learn where the functional languages shine.

    -Chris

  • http://codebetter.com/blogs/jeremy.miller Jeremy D. Miller

    @Lionel et al,

    Wow, thank you for that. I’m already looking at the coursework at the Cambridge site. My biggest goal is to really learn the Functional paradigm instead of just writing OO in F# much the same way that Fortran/COBOL developers write procedural code in C#/Java today. I’m not really concerned with the end product, just the journey. With the functional stuff leaking into mainstream languages and the multi-multi core machines coming up, functional programming seems to be a good line of inquiry. At least until IronRuby is a bit more baked.

    P.S. Prolog is definitely out for awhile. My only exposure to a monotonic rules engine was so negative that I want absolutely nothing to do with Prolog.

  • Lionel

    F# is a dialect of ML so while these are links to ML resources they should be fairly relevant. I learned how to use functional programming with this course :

    http://www.cl.cam.ac.uk/teaching/current/FoundsCS/

    Which is a little basic as it assumes no programming knowledge but moves quickly has well written notes and it has lots of example questions.

    If you want a good book this one is good.

    http://www.amazon.co.uk/ML-Working-Programmer-Larry-Paulson/dp/052156543X

    I bought it when I was a student and thought it was a bit rubbish but now I have become a more experience programmer I have been rereading it and it is really excellent. If you are serious about functional programming then I would really recommend getting a copy.

    If you think that OO programming and functional programming are different was of solving problems then I think I would disagree. I always think of OO as a way or organizing programs whereas functional programming is a different way of coding algorithms. But it is wrong to think of languages like f# and ml as pure functional languages as they can do imperative stuff too!

    The functional language ML was developed to build theorem provers so if you want to really see what functional languages are good at then you should build one of those :). ML for the working programmer has some example projects in the back but they have a strong theoretical computer science slant (one of them for example is to but a theorem prover). Not all I do is program c#, SQL and winforms these days so it should be telling you how completely useless all this theoretical stuff is and how in the real world nobody uses any of this stuff (I certainly don’t) but I honestly think there is a lot to be said for look doing a more theoretical project like a theorem prover. After all we spend most of our lives solving the same problems over and over again like writing a content management system, writing revenue reports and finding slight better working processes. We get a bit better at doing these each time but when you have been in the industry for a while you will have the the most problems before (not all problems obviously). Admittedly each time it is there is a slightly different slant but the general problems remain the same. This means you build up a standard way of solving these problems based on the way you have seen others do them and the ways that have worked for you in the past. If one really wants to grow as a programmer I think you have to find radically different problems to solve and see the way that people have approached those problems. This kicks you out of that comfortable little world that we all like to program in and means makes you start having to think again. It also means you get a completely a whole new set of standard solutions to problems which will make you as a programmer much more effective. After all you will now have many more ways of solving problems. All this sound a little abstract so some examples. Why learn ruby it is after all just another imperative language with slightly different syntax. It might let you solve problems a little quicker than c# and be a little bit more flexible but it isn’t that radically different. Instead why not take the time to learn Prolog. This is a completely different way of thinking about how to do programming. It might not be a immediately useful as ruby but it sure as hell is going make you think differently about ways to solve a certain class of problems.

    Anyway coming back on topic If you have never written a syntax checker before then writing it in f# is not a bad idea but you will probably write if faster in c# and more people will be able to help you maintain it. You would probably find it more useful to do something really off the wall and write something like a theorem prover in F#. Since ML evolved to write theorem provers when you write one then you will understand the mindset of a theorem prover writer. This will really give you an incite into why they invented ML and understand the mindset of solving problems in that way. Understanding theorem proving will also give you a new way of solving a certain class of problem (where you have a problem and you know where you want to go but don’t know how to get there). Knowing more methods of how to solve problems can only be a good thing.

    Hmm having just reread this comment it all sounds a bit pompous and not very useful but it is so seldom I write anything these days I may as well post it anyway :)

    Lionel

  • http://peter@ipacs.hu Peter Ipacs

    Hi Jeremy,

    I’m not a guru but I use haskell to:
    - do pattern matching (extracting data from various formats, pretty printing, conversion, etc.)
    - process mass data (generate report data and other statistics from huge datasets … up to hundreds of MBs not TBs though:)

    And playing of course:)

    P

  • http://andrewpeters.net Andrew Peters

    Hi Jeremy,

    Other problem categories ideal for functional are:

    - Processing very large data sets. E.g. There is a team at MS processing 7TB data sets using 100 LOC F#. This is, of course, enabled through Lazy Evaluation.
    - Concurrency-oriented programming. No side effects makes concurrent programming easier. Maybe StoryTeller could partition test execution over a large map/reduce cluster ;-)

    Cheers,

    Andrew.

  • Trystan

    As a C# and Haskell fan I’d say functional programming makes parsing and syntax trees easy to use. There is a book about implementing your own functional language that has a few chapters on parsing, pritty printing, and working with data that represents code in another language. It’s written in Miranda, but most functional languages are similar enough.

    http://research.microsoft.com/~simonpj/Papers/pj-lester-book/

    Keep us updated!