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? - Hal -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
hi, the haskell report says that a program should contain a module called "Main", which should export a function called "main" of type IO(). there is no requiremnt however that the function "main" is defined in the module "Main", it could for example be imported from somewhere. so in your situation you could have a module "Main", which just imports the module where the "main" function is defined (don't forget to also export "main") and than you won't need to rename your module all the time. having said all that, there seems to be a bug in ghc (or perhaps an implementation restriction), which requires that "main" is defined in the module "Main". the only other haskell implementation i have access to is hugs, and in this respect it behaves correctly, but alas it has other issues with the module system. bye iavor On Fri, Nov 16, 2001 at 06:34:14PM +0000, Hal Daume wrote:
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?
- Hal
-- Hal Daume III
"Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- ================================================== | Iavor S. Diatchki, Ph.D. student | | Department of Computer Science and Engineering | | School of OGI at OHSU | | http://www.cse.ogi.edu/~diatchki | ==================================================
On Fri, 16 Nov 2001, Iavor S. Diatchki wrote: (snip)
having said all that, there seems to be a bug in ghc (or perhaps an implementation restriction), which requires that "main" is defined in the module "Main". the only other haskell implementation i have (snip)
Actually, what would be nice in ghci is to be able to :load modules that don't have "main" defined. Followups should probably go to one of the GHC lists though, I guess. -- Mark
Strange, I'm not annoyed by this at all though I supposed to be. First I make module alone, and have 'module Main' and 'main' function there, then I use it in project, and change the name to whichever I want and rename or delete the 'main' function. Anyway there can be a workaround (I didn't try it): ===== Module.hs #ifdef Module_MAIN module Main where #else module Module where #endif <..> #ifdef Module_MAIN main = test_main #endif <..> ===== end ===== Makefile <..> GHC_MAIN_MODULES=Module1 Module2 <..> GHC_OPTS+=-cpp $(GHC_MAIN_MODULES:%=-D%_MAIN) <..> ===== end (that's GNU make, I don't know if this works in other. If don't, just add the options -D<Modulename>_MAIN directly) Then the only thing you have to change is the first mentioned line in the Makefile. Max.
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-)
participants (5)
-
Hal Daume -
Iavor S. Diatchki -
Keith Wansbrough -
Mark Carroll -
Max A . K .