[Haskell-cafe] Modules and files

ajb at spamcop.net ajb at spamcop.net
Tue Jun 15 20:37:44 EDT 2004

G'day all.

Quoting Jerzy Karczmarczuk <karczma at info.unicaen.fr>:

> Question of perspective... In Pascal, Modula, Python, Clean,
> you name it, modules and files were always 1 - 1.

A C++ class is basically an instantiable module.  In C++, you can
implement more than one module in a file, and you can implement a
single module in multiple files.

> Somehow
> this is considered more 'clean', isn't it?

It's usually considered good design practice in languages with modules
to have one module responsible for one thing.  Sometimes this is not
possible, for example, if a module is responsible for implementing a
major internal abstraction (e.g. "Core" in GHC, "database" in a database
server etc).  In that situation, it makes sense to distribute
implementation of a module across more than one file.  In Haskell, of
course, you can do this by re-exporting symbols from imported modules;
the Prelude is a case in point.

Similarly, if a module is considered "private", such as with nested
modules (or nested classes in C++), it is arguably cleaner to implement
them privately lest someone else import them and use them.  This
usually means within the module which uses it, i.e., more than one
module per file.

> What's the problem with editing and displaying multiple files?

This reminds me of a previous discussion of tab stops for some reason.

I feel like saying "here's a nickel, kid... buy yourself a decent text
editor", but that's a bit rude.  More nicely: It's not the programming
language's job to take up the slack where your specific text editor is
lagging, especially when I can name about half a dozen editors off the
top of my head which can handle multiple files perfectly well.

> I believe that our 21st century should finally forsake the old
> concept of file, as we see it now. A module is an entry in a
> database.

Be careful, lest you end up with a multiple maintenance problem.  The
reason why text files haven't gone the way of punched cards yet is that
they're uniform and simple, and they're easy from a management point of
view (one text file is one work assignment to a programmer in a team).

> We have already separate 'interface files'...

...which are automatically generated.

Andrew Bromage

More information about the Haskell-Cafe mailing list