[Haskell-cafe] Re: Weird ghci behaviour?

Simon Peyton-Jones simonpj at microsoft.com
Tue Nov 13 06:00:03 EST 2007

| "For technical reasons, GHCi can only support the *-form for modules
| which are interpreted, so compiled modules and package modules can
| only contribute their exports to the current scope." But it does mean
| the interpreter isn't referentially transparent, which is weird for a
| language that puts so much stress on referential transparency.

Well it depends on what you mean by "referential transparency" -- but I'll agree 100% that the behaviour you described in your original message is surprising, and therefore unwelcome.

Nevertheless, I think there's a good reason for it.  The "technical reasons" are not just laziness on our part.  By exporting only the functions named in the export list, GHC can inline everything else vigorously, and that can in turn give big performance improvements.  We don't want to arrange that every top-level definition is treated as exported *just in case* someone wants to GHCi that module.

This is behaviour that could be changed. E.g. we could say that the top-level scope remains available unless you optimise with -O2.  Or something.  But there has to be a surprise lurking somewhere.

It's just another of those things on GHC's now-large surface area that could probably be improved if someone sat down and thought about it carefully.

Meanwhile, though, the best we can do is improve the documentation:

        Dan, can you suggest any words we could add to the
        documentation that would have prevented you stumbling?


More information about the Haskell-Cafe mailing list