not naming modules Main

Hal Daume hdaume@ISI.EDU
Mon, 19 Nov 2001 17:19:16 GMT

Coming up with proposals is always much more difficult that simply
complaining about something.  Here is a proposal which seems
reasonable to me (and implementable):

     Allow any module to have a main function.  When you compile (with
     ghc), and you say, for example:
      % ghc --make Foo.hs -o Foo
     then it looks in Foo.hs for the main function (regardless of
     whether the name of the module appearing in Foo.hs is Main or
     Foo).  As I never use ghc without the --make option, I'm not sure
     how this would roll over when not using it.  Perhaps there could
     be an option like:
      % ghc Foo.hs Bar.hs FooBar.hs -o Foo -main-in Foo.hs
     or something where you can specify which module has the main you
     want to use.

     Then, say you have two modules, Foo.hs (containing module Foo)
     and Bar.hs (containing module Bar), both with main functions,
     suppose Foo is the one from which the desire main function comes,
     you can always "import Bar hiding (main)".

In fact, the -main-in xxxx.hs could simply direct the compiler to,
when reading xxxx.hs, rename the module to be Main...well, not
quite... that would result in some problems when you said xxxx.f for
some other function.  But it could simply "create" a dummy "file" (not
really a file -- more in memory" that's something like:

  module Main(main)

  import qualified xxxx (main)

  main = xxxx.main

or whatever.

Does this seem reasonable?  I can't think of any code it would break.

 - Hal

   content-class: urn:content-classes:message
   Content-Type: text/plain;
   Date: Mon, 19 Nov 2001 01:07:23 -0800
   X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3
   Thread-Topic: not naming modules Main
   Thread-Index: AcFuzX2vH7im90E2QrWw7IdFvlSE8wCC1SCQ
   From: "Simon Peyton-Jones" <>
   Cc: "GHC users (GHC users)" <>
   X-OriginalArrivalTime: 19 Nov 2001 09:07:24.0600 (UTC) FILETIME=[9A897B80:01C170D9]
   X-MIME-Autoconverted: from quoted-printable to 8bit by id fAJ97eg28990

   (Moving this to GHC users.)

   What exactly do you propose?

   * Haskell allows you to define a 'main' in any module you please.

   * GHCi allows you to execute any of these 'main' functions
     (You get all the speed of compiled code if you compile the module
     first and load the compiled module into GHCi.)

   * But if you want to link together a bunch of modules into an
     there must be some way to decide which 'main' you want to execute.
     Haskell's way is to say "It's the 'main' from module Main".  

   We like feedback about what would be useful -- GHC has lots of things
   that aren't exactly Haskell that were generated by such suggestions.
   But I'm unclear what you would like (let alone how easy it would
   be to implement).


   | -----Original Message-----
   | From: Hal Daume [mailto:hdaume@ISI.EDU] 
   | Sent: 16 November 2001 18:34
   | To:
   | Subject: not naming modules Main
   | 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    |
   |   than astronomy is about telescopes." -Dijkstra |
   | _______________________________________________
   | Haskell mailing list

Hal Daume III

 "Computer science is no more about computers    |
  than astronomy is about telescopes." -Dijkstra |