Main.main naming convention

Koen Claessen koen@cs.chalmers.se
Tue, 10 Sep 2002 11:47:24 +0200 (MET DST)


Martin Norbäck <d95mback@dtek.chalmers.se> wrote,

 | I have a question about the Main.main naming
 | convention. Would it be a good idea to lift the
 | restriction and allow any module which exports a
 | function main :: IO () to be compiled into a separate
 | binary?
 :
 | Why I'm asking is because I have several Main modules
 | in one directory, in files like Program1.hs,
 | Program2.hs and so on, but all of these claims (and
 | must claim) to be "module Main".

A work-around is to call these modules Program1, Program2,
and then have one extra module in, say, Main.hs:

  module Main where

  import qualified ProgramX

  main = ProgramX.main

Of course one can change X to be 1, 2, ...

But I agree it seems a somewhat arbitrary restriction.

Another such restriction is the fact that any module which
is called Main *must* have a function which is called main
in it. In combination with the rule that says that any
module which is not explicitly named is called Main, this
gets very annoying when using an interactive Haskell system
such as ghci. (I don't think that Hugs does insists on
this.)

This restriction will go too if the main module can have
whatever name.

/Koen.