[Haskell-cafe] First steps in Haskell

Sebastian Sylvan sebastian.sylvan at gmail.com
Sun Dec 18 12:18:33 EST 2005


On 12/18/05, Daniel Carrera <daniel.carrera at zmsl.com> wrote:
> Lemmih wrote:
> > 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`).
>
> I would expect GHC to be able to compile a program with a function that
> is not called 'main'. I wouldn't expect it to print anything when run,
> but I would expect it to compile.

It can. To compile a module use the "-c" ('c' for "compile"). If you
want an executable you will need to have an entry-point (which is
main).

Typically you would write your program in a file, have a main
function, and then write

ghc --make MyMainModule.hs -o MyExecutableName

Optionally adding "-O" or "-O2" for optimisation.

The "--make" flag is really useful as it will cause GHC to track down
dependencies automatically and compile them if needed (reducing the
need for makefiles etc.).

/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list