Thursday, 8 September 2016

A look at haskell

Recently I got some time on my hands so I started looking at programming in Haskell. I have heard of haskell a few times from academic people but never truly understood the syntax. Last week I was at a programming language debate. Haskell did have some good points so I thought I would at least understand the basics of the syntax. Just in case it was useful in the future and improve my pure functional programming skills

How I approached learning it
First I always try the hello world example. I learn two things this way. How to compile and execute  and how to print out to standard out. Printing to standard out helps with debugging. When learning a new language putting a few debugging message helps you see the flow of the program. It also shows where the program was before the failure and the values of the variables.

Next I try a few simple maths equations. Then I jump in to calling functions or methods.
  • First with no return type or arguments
  • Then with a return type. Usually returning an integer for simplicity.
  • Then with a return type and arguments. The are not linked. Just to avoid any computation problem. More concerned with getting the in and out correct first.
  • The with a return and arguments. The return is based on the arguments supplied.
Once I mastered the above then I have a basic know the of the syntax and how everything runs. I am no master at this point but a good foundation.

Thoughts on haskell while learning from scratch:
  • Has 2 ways of defining and calling functions. Makes it confusing when looking at different tutorials
  • For a beginner haskell has a lot of builtin functions. There is no way to tell the difference between defined function and a builtin which knowing the builtin functions. In java you can check were the import came to see if it came from the core library.
  • The compiler errors are hard to decipher for a beginners. It is better to start with a correct program with customizing and constant compiling. 
  • I  am not a big fan white spaces to separate arguments. I prefer to have parentheses for better readability. Also I prefer curly braces to group information instead of indentation. You can do these in haskell but white spaces and indentation seem to be the normal for less verbose code.

Here are 2 resources that I found useful.

 I uploaded my small haskell programs. It might help a beginner.


No comments:

Post a Comment