[Haskell-cafe] Re: module names

S Koray Can skoraycan at aim.com
Thu Dec 15 22:32:47 EST 2005

Scherrer, Chad wrote:
> module Main where
>     import A
>     import B
>     main = A.f >> B.f
>   module A where
>     f = ...
>   module B where
>     f = ...
> in a single file. This example is straight from chapter 5 of the Report,
> and no mention is made (that I could find) about modules needing to be
> in separate files. But this won't load in ghci! (Even if ... is changed
> to putStr "hi"). Eventually I figured out that it works fine if it's
> split over three separate files.

The report says that they make up a single program, so that does not 
imply that they are in a single file. But, you are right: it's a good
idea to be explicit about this.

> So here's what I'm trying to figure out: If every file corresponds to
> exactly one module (is that true?), then why must the module name be
> given again in the text of the file? When I'm using ghci, I have lots of
> modules that I sometimes want to load "as Main", and sometimes I only
> want them loaded as a dependency from another module. Currently, I have
> to go into each file to change the "module Foo where" line to do this.

Section 9.5 of the report seems to show that <module> stands for the 
compilation unit and it defines a single module. I suppose the standard 
allows you to name your module freely no matter your filesystem allows, 
but ghc requires (afaik) that module M exist in M.hs or M.lhs.
Why not do this: name none of those modules Main.hs, and have an empty 
module Main.hs with only "import MainDeJour" and "main = 
MainDeJour.main" so you can just edit just that file.


More information about the Haskell-Cafe mailing list