10 Apr 2007
Adventures In Haskell – Part I
I decided I should expand my computeristic knowledge and pick up a new language. Up for consideration were: lisp, haskell, and flash (action script). Lisp I have a strong interest in, but not strong enough to overcome my aversion to something that you pay for. Action script would probably be the most useful, in a directly relevant to my life way, to learn. In the end I settled for haskell. It is supposed to blow my mind and be a zen like experience that will take me to the next level of programming gurudom.
I googled for ‘learning haskell’ and ended up at the official haskell learning page. After browsing the options I decided to go for the tutorial called, ‘Two dozen short lessons‘, and download hugs as my haskell environment. So far so good.
I’ve never done any functional programming of any kind, so I had no idea what to expect. Erik has tried to show me a few things, but I’m the type of person who learns to do by doing. Most of the things he showed me I thought were neat conceptual tricks with no real reason for existing. I’m a good little sheep, so when the tutorial told me to forget everything I know about functional and object oriented programming I did so. With great ease and joy for the object stuff as well.
I’m on page 70 of the tutorial and so far I have found one main thing that annoys me. The way haskell is set up means that I can’t just write definitions (raw code) into the interpreter like I would Python. I have to do that in a text file and then load it. From there I can run commands on the code. So I can use the functions I define, but I can’t define them in the interpreter for a quick putter. Annoying, but not nearly as annoying as the fact that I can’t declare variables in the interpreter as well. I’m learning the way and the why of haskell so it makes sense to do it this way, but I’m lazy and it’d just be easier to write it right in.
I’m understanding how things work, and I’ve taken their examples and mashed them up to do my own thing differently, but I’m not sure I grok it yet. Most other coding tutorials I’ve done have started out with a hello world program. Haskell has dived right into sets, list comprehension, reductions and infinite iterations while briefly stopping to talk about the nature of numbers. It’s not making my head hurt as much as I thought it might, but there is still some pain.
So far I’m not seeing any real advantage to haskell as a language, but I’ve only started scratching the surface and the syntax. I’m seeing it more as a tool for doing computations like statistics than as a general language useful for everything. I’m going to keep at it and see if I can’t think up a project to do in haskell that solves a real problem.
Cale Gibbard on April 16th, 2007 at 8:00 pm
Hello! It’s always good to hear about a new Haskell user!
The best way to learn is to come and join us on IRC on irc.freenode.net #haskell — it’s very newbie-friendly, and we’ll be happy to answer any questions you might have.
If you’re having trouble finding resources for learning, a couple of the better ones which I’d recommend starting off with are the Wikibook ( http://en.wikibooks.org/wiki/Haskell ) and “Yet Another Haskell Tutorial” ( http://en.wikibooks.org/wiki/Haskell/YAHT ). A good meta-resource is http://haskell.org/haskellwiki/Books_and_tutorials
Note that a common set-up for writing Haskell code is to just keep two windows open at all times — your editor and the interpreter/interactive environment you’re using. Hugs and GHCi both make it qiute easy to reload your file when you make changes (in hugs, :r wil reload, and in GHCi you can reduce that to just a single colon.). If you use GHCi, you can make temporary function and value definitions by prefixing them with ‘let’, but I still find that putting things in a file usually works better, as it means that you don’t end up losing work when a command ends up printing unbounded amounts of output.
Anyway, good luck with Haskell, and make sure to join us on IRC!
– Cale