Installing Haskell

Advertise Here

, ,

Go to http://www.haskell.org/ghc/ and download and install the Glasgow Haskell Compiler for your operating system.

On Mac OS X, this means you download a “.dmg” file, open it, and run the installer.

Once installed, go to your command line interface (in OS X, it's the Terminal application) and type “ghci”. That would start up the Haskell interpreter. Now you can type “1 + 2” to evaluate it. To exit, type “exit”.

Run a Haskell Program

Creat a file “test.hs” and in it put:

fac :: Integer -> Integer
fac 0 = 1
fac n | n > 0 = n * fac (n-1)

Now, in terminal, cd to the same directory the file is at, start ghci, and type:

:load test.hs
fac 3

You will see it's output is 6.

In ghci, commands to the interpreter are prefixed with a colon “:”. The command “load” loads a file. To see other commands, type “:help”.

http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci.html

blog comments powered by Disqus
2005-11