Skip to content

Haskell

Installing Haskell on your Mac

Every example has to start with Hello, World!, the first example is using the Haskell REPL ( or interactive. mode )

The alternative, more traditional approach is to use the Haskell compiler to create a binary. In a file called hello.hs add the following text

Then compile and execute the binary

Basic Syntax:

In Haskell, a function is defined using the following syntax:

For example, to define a function that adds two numbers, you could write:

You can also define a function that takes no arguments, like this:

To call a function, you simply write the function name followed by the arguments in parentheses:

This will set the variable “result” to 5.