separate compilation [was Re: Global variables?]

Jon Cast jcast@ou.edu
Wed, 05 Feb 2003 21:28:05 -0600


Andrew J Bromage <ajb@spamcop.net> wrote:
> G'day all.

> On Wed, Feb 05, 2003 at 08:05:56PM -0600, Jon Cast wrote:

> > I'm not sure I follow this.  If you change the type of a value exported
> > from a given module, that's a public change, no?  And if you don't, why
> > should re-compilation be needed?

> Consider this:

> <<
> module A where

> import B

> {- use B.b -}
> >>

> <<
> module B (b) where

> import C

> b = C.c
> >>

> <<
> module C (c) where

> c :: Int
> >>

> Changing the type of c requires recompiling module A.

> You would expect that changing c's type forces a recompilation of B,
> since you changed C's public interface.  However, this also changes
> B's public interface even though you did not touch the text of module
> B.  The reason is that B's public interface is partly based on modules
> which it _privately_ imports, even if it does not re-export any
> symbols from those modules.

I think I see what you're saying.  I still maintain, however, that,
since you've changed the type of B.b (admittedly implicitly), and B.b is
exported from B, that you've changed B's interface.

There is a reason make is designed to re-build B /and/ (potentially) A
when C changes, after all.

> One fix is to require all exported symbols to have explicit type
> declarations.  Since this is good practice anyway, I would be in
> favour of making it a language requirement in Haskell 2.

> Cheers,
> Andrew Bromage

Jon Cast