Fork me on Github

Fork me on GitHub

Apr 20, 2012

Starting with Haskell

First disclaimer/setting of context. I am a beginner when it comes to Haskell, so this post will not contain any deep insights into the Haskell language, rather some links, tips and tricks and code snippets that I have been playing with during my first hours discovering the language.
(the purpose of this write-up is a note to self and hopefully it can also help other beginners to get started with the basics)



A really useful resource that I have spent some time with, both reading full sections and using as a reference, is learnyouahaskell.com. It is a book published in its entirety on the web and that also can be bought if you find a soft copy easier. Another good a freely available book is Real World Haskell.

Getting Haskell going on a PC has proved to be easy, I just went to haskell.org and downloaded the Windows version. From the Win Haskell package I use WinGhci, which seems very stable and is straight forward to work with. If you come from an FSharp background, you can think of this tool as the FSharp interactive window that you are used to from Visual Studio.

A gotcha is that you need to use the ghci specific let keyword to make definitions in the interactive window.

Some commands, more focusing on the handling of the IDE than actually showing any Haskell (the book examples are the best resource for that).

To toggle type display in ghci:


to load a haskell file (file extension .hs)

To find out details about a name, you can use the :info ghci command, more details here.

A really useful resource to find out more about Haskell commands, is hackage. This can be used as a programming reference. I have used it to find out more about the Base package, which is the standard package that is loaded whenever you start Haskell.

A syntax that has stood out to me as really powerful so far in Haskell is List comprehensions. You can surely  find better and more detailed explanations of it here and here, but in short you specify an output function and generators/predicates. The syntax looks like this:


List comprehensions can be very useful for solving combinatorial problems.

Another really useful resource is Hoogle. It is a search engine for haskell functions and great help as a syntax reference.




No comments:

Post a Comment