main modules in GHC, deriving differences between GHC and Hugs

Hal Daume III hdaume@ISI.EDU
Fri, 13 Jun 2003 13:06:50 -0700 (PDT)


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                                   | hdaume@isi.edu
 "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 (m.p.donadio@ieee.org)
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>