[Haskell-cafe] module names

Scherrer, Chad Chad.Scherrer at pnl.gov
Thu Dec 15 13:00:41 EST 2005


Something about the way module names are specified in a file seems
really strange to me. When I first started learning Haskell (I had used
OCaml previously), I tried things like

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.

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.

Chad Scherrer


More information about the Haskell-Cafe mailing list