The question of conveniently naming a function to use as the 'main' function has come before. I've implemented a -main-is flag for GHC, so you can nominate either the module containing the main function, or the main function name, or both.
The change is in the repository, and it's documented in the manual. I hope this'll help the test-suite folk. Simon | -----Original Message----- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hal Daume III | Sent: 13 June 2003 21:07 | To: Matthew Donadio | Cc: Graham Klyne; Haskell Mailing List | Subject: Re: main modules in GHC, deriving differences between GHC and Hugs | | Yes, but there's a problem with this solution. Namely, if Foo.hs takes a | long time to compile, then you can't leverage having already created Foo.o | and Foo.hi when making the Main. | | The solution I use is a script that you call like: | | ghcmake File | | which creates MainXXX.hs (where XXX is a random number) and this contains: | | module Main where { import qualified File (main) ; main = File.main } | | It then runs ghc --make on that and deletes the MainXXX.hs file. | | This works okay, but isn't very satisfactory. | | Personally, I think this is stupid and that you should be able to compile | any module with a 'main :: IO a' function as an executable without having | to call it Main. You can probably find a message from me to this extent | in the archives, as well as some response. | | - Hal | | -- | Hal Daume III | [EMAIL PROTECTED] | "Arrest this man, he talks in maths." | www.isi.edu/~hdaume | | On Fri, 13 Jun 2003, Matthew Donadio wrote: | | > Graham Klyne wrote: | > > GHC seems to require a 'main' module in a file in order to generate an exe | > > file. This makes it awkward to create unit test programs, because I | > > generally create one (to run stand-alone) for each major module. Now I | > > want to create a "master test" module that runs all the individual module | > > tests. But if the module tests are all "main" modules it seems I cannot | > > bring them all together into a larger program. Have I overlooked any way | > > to create an executable program from any module containing a main function | > > of the appropriate type? | > | > The easiest way to handle this is to run all the source through the C | > preprocessor, and put #ifdef's around main and the module name. | > Something like | > | > #ifdef UNIT_TEST | > module Main where | > #else | > module Foo where | > #endif | > | > foo x y = x + y | > | > tests = [ foo 2 3 == 5, | > foo 3 4 /= 6 | > ] | > | > #ifdef UNIT_TEST | > main = print $ and tests | > #else | > foo_test = and tests | > #endif | > | > I haven't done this with Haskell, but I have done it with a lot of my C | > libraries. | > | > -- | > Matthew Donadio ([EMAIL PROTECTED]) | > _______________________________________________ | > Haskell mailing list | > [EMAIL PROTECTED] | > http://www.haskell.org/mailman/listinfo/haskell | > | | _______________________________________________ | Haskell mailing list | [EMAIL PROTECTED] | http://www.haskell.org/mailman/listinfo/haskell _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
