[Haskell-cafe] First steps in Haskell

Lemmih lemmih at gmail.com
Sun Dec 18 11:32:55 EST 2005


On 12/18/05, Daniel Carrera <daniel.carrera at zmsl.com> 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)
>
> This is what I see:
>
> $ hugs
> Hugs.Base> fac :: Integer -> Integer
> ERROR - Undefined variable "fac"
> Hugs.Base> fac 0 = 1
> ERROR - Syntax error in input (unexpected `=')
>
>
> $ ghci
> Prelude> fac :: Integer -> Integer
>
> <interactive>:1:0: Not in scope: `fac'
> Prelude> fac 0 = 1
> <interactive>:1:6: parse error on input `='
>
> $ # Write the program to fac.hs
> $ ghc fac.hs
>
> fac.hs:1:0:
>      The main function `main' is not defined in module `Main'
>      When checking the type of the main function `main'

GHC is a compiler. If you want to compile to a binary then you must
define a function called 'main'. Otherwise just load the file in ghci
(`ghci fac.hs`).

--
Friendly,
  Lemmih


More information about the Haskell-Cafe mailing list