Minsky and Housing Bubble
What would Gandhi Really Do?

Learning Haskell

I stumbled onto Haskell around 2 months back while searching for resources on spreadsheet programming.

I wanted to do Buy vs Rent calculations before deciding to buy a house. Microsoft Excel is pretty good. However, after a while it simply did not scale up. You cannot define your own functions and there are no local variables available. It has been my experience that learning in the context of real problem is much faster and easier. This time, it launched my exploration of functional programming. Enter Haskell.

Haskell is a pure functional programming language. Transition from imperative programming to functional programming (and too a pure one) was very difficult. But slowly, I got the hang of it. I re-did Buy vs Rent calculations in Haskell (it's not complete yet).

To explore Haskell further, I decided to implement a small subset of GNU Make features in Haskell. Within a few days (1 day of "thinking" and reading, followed by a day of coding), I was able to get a working system (see make.hs). To use it, simply call 'make' function, passing it a list of rules and a target:

make [(makeCCRule "test")] "test.o"

Simple, C compilation and linking rules are included. But you can define your own rules (a tuple of dependencies, target and list of commands to run when the target is out of date with its dependencies). Haskell allows you to focus on your application logic without causing undue distractions of memory management, maintaining state or even declaring types (it provides type inferencing). It is amazing how much you can do in less than 90 lines of Haskell code (including comments and empty lines). 

I haven't tested it thoroughly and there is no error handling. The system is easy to extend with your own "definition" of what it means to have a target out of date with its dependencies. With a little bit of refactoring it won't be that hard to support pattern like rules (.c to .o, etc.). Please send me feedback on how to improve this (I would love more modularity using type classes, for example).

Comments

helen2008

Hi, The article learning about hastell is very interesting. I want more details.

=========

helen

Comprehensive resources for those looking for recovery from addiction.

http://www.addictionrecovery.net

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)