not naming modules Main

Keith Wansbrough
Mon, 19 Nov 2001 12:49:31 +0000

> I'm really frustrated that modules that you want to compile to
> executables have to be named Main.  I often have a module with a main
> method that I use for testing or whatever (perhaps I want the gained
> speed of an executable) but is, for the most part, a module I import
> into others.  I end up having to constantly change the module name
> whenever I want to compile it and I find this terribly frustrating.
> Is there any reason you can't just compile things that simply export a
> main method with the proper type?  Is this a ghc specific thing or
> does nhc also have this restriction?  Any chance ghc will change its
> policy on this?

In GHC the "main" method has to be in module "Main", but there is no
requirement that the *file* containing module "Main" is called "Main".
Since "Main" isn't (usually) imported by any other module, there's no
concern that GHC won't be able to find the module when it looks for
it.  So you can have "Main.hs" with the real main in it, and
"TestMain.hs" with the alternative one, and just compile the right
file as appropriate.

However, after having written the above I'm not sure it answers your
question... sorry!

--KW 8-)