Ads




Profiles

Blogroll



  • Ashish's Niti - Old Blog

Your email address:


Powered by FeedBlitz

« Minsky and Housing Bubble | Main | What would Gandhi Really Do? »

March 10, 2007

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).

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/330304/16785380

Listed below are links to weblogs that reference Learning Haskell:

Comments

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

Post a comment

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

If you have a TypeKey or TypePad account, please Sign In

Subscribe




  • Subscribe to my RSS feed

  • Enter your Email


    Preview |

Tip Jar



  • Amazon Honor System Click Here to Pay Learn More

Ashish's shared items in Google Reader

Search


  • Google

  • Search Now:
    Amazon Logo

BookShelf - Recently Read

September 2007

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Blog powered by TypePad