[Haskell-cafe] First steps in Haskell

Chris Kuklewicz haskell at list.mightyreason.com
Sun Dec 18 11:39:50 EST 2005

Daniel Carrera wrote:

>> Hello all,
>> I'm trying to write the simplest possible Haskell program, and I'm not
>> getting anywhere.
>> I have installed Hugs, GHC and GHCI. I want to run the following program:
>> fac :: Integer -> Integer
>> fac 0 = 1
>> fac n | n > 0 = n * fac (n-1)

$ ghci

Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n *
fac (n-1) }
Prelude> fac 12

>> This is a real problem for Haskell. I expect that a lot of people try
>> Haskell and give up because they can't even write the simplest function.
>> It's hard not to be put off by this. I love the theory behind Haskell,
>> but the practice of it seems to be a real problem.
>> I hope someone will show me how to make this program work. Even better,
>> I hope someone will fix the compilers and interpreters if they need
>> fixing, or fix the documentation if that's what needs fixing.
>> Best,
>> Daniel.

Almost everything is explained under


The main things is: The ghci prompt accepts either command, starting with
a color such as :load
"filename" or haskell IO code, since it is in a do-block. Thus let is

The 2-D Layout syntax does not work at the ghci prompt, thus the
braces-and-semicolon style I used.

More typically you would write your code in a file, as shown in:

More information about the Haskell-Cafe mailing list