Mutually recursive modules

From HaskellWiki
Revision as of 14:03, 6 February 2009 by Lemming (talk | contribs) (compiler limitations)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Mutually recursive modules are modules that import each other. This way it is not possible to find a sequence to compile them one after another. This is a typical problem of languages with a strong module system, in contrast to languages like C, where all parts of a program are merge textually by the preprocessor before compiling them.

Simple example:

module A where

import B


module B where

import A

If possible, mutually recursive modules should be avoided, since they obscur things. Once you have mutually recursive modules in a package, you will no longer be able to put modules of an import cycle into different packages, because mutually recursive packages are not supported.


Compiler support

The Haskell 98 report says, that Haskell 98 allows mutually recursive modules, but not all compilers support them completely or even in a simple way.

GHC

GHC supports mutually recursive modules in a limited way and requires additional information. You must break the data dependency cycles manually by creating .hiboot files. Up to version 6.10 it is not possible to create mutually recursive class definitions across modules, e.g.

module A where

import B

class B t => A t where
   ...


module B where

import A

class B t where
   f :: A t => t -> t


Hugs

Hugs until September 2006 does [http://cvs.haskell.org/Hugs/pages/users_guide/faq.html#AEN1926

not support] mutual recursive modules.