Cupid

Inside Cupid

Modules, files and the search path

How Cupid turns a module name into a file, what the current module is, and why the default search path looks the way it does.

One module per file

Cupid keeps each module in its own file and does not support mutually recursive modules. A file may be loaded by its path, in which case it may contain a module of any name, or by its module name, in which case Cupid has to find it.

To find module M, Cupid tries dir/M.hs and then dir/M.lhs for each directory dir on the search path, in order. A hierarchical name is mapped to a path: A.B.C becomes dir/A/B/C.hs. The suffix list is the -S option and the search path the -P option. A .lhs file is a literate script, read as The language Cupid accepts describes.

Imports are chased

Loading a module loads the modules it imports, recursively. A module loaded by file name makes its own directory a root for its imports: that root is tried before the search path, and a module found under it passes the same root to its own imports. So

Cupid> :load /path/to/project/Main.hs

resolves import A.B.C to /path/to/project/A/B/C.hs without the project directory being on the search path, and an import D in A.B.C to /path/to/project/D.hs. Modules found on the search path proper do not get this extra directory; their imports are resolved from the search path alone.

The default search path

On Linux and macOS it is:

.:{Home}/lib/cupid/packages/*:/usr/local/lib/cupid/packages/*:{Cupid}/packages/*

On Windows it is .;{Cupid}\packages\*, with no home or system-wide entry.

The current directory comes first, so a project's own modules shadow everything. {Cupid} is the library directory and its packages/ holds the two shipped packages, base and cupid; dir/* means every immediate subdirectory of dir, so each package's root is a search directory and a module Data.Map is found as packages/base/Data/Map.hs.

On Linux and macOS the two other packages/* entries exist for libraries you add. One is under your home directory, the other is the system-wide location. A library is a directory of modules copied under either; there is no package database and nothing to register. This is what remains of the Cabal support of the 2006 release, which installed packages into these directories.

Cupid refuses a search path or suffix list from which the Prelude cannot be found, so :set -P cannot lock you out of the interpreter.

The current module

Expressions at the prompt are evaluated in the scope of one module, the current module, which the prompt names. At start it is Cupid, an empty module that exists only for this purpose. :load and :also make the last module loaded current; :module changes it.

The scope is the module's whole top level, not its export list, so names the module does not export are usable at the prompt. This is deliberate: when experimenting, being able to poke at the internals of the module you are writing is worth more than a faithful simulation of what importers see. It does mean that an abstract type is not abstract at the prompt of its own module.

Only one module is current at a time. To have several in scope, write a module that imports them and make that one current.

Why Cupid.Prelude

Haskell defines the Prelude and the standard libraries as mutually recursive, which Cupid does not support. Instead almost everything the Prelude exports is defined in Cupid.Prelude, which the Prelude and the library modules import. This is why :names shows Cupid.Prelude.map rather than Prelude.map, and why an error message may mention Cupid.Prelude.

See also

Edit this page on GitHub