instance visibility (was: Re: The base library and GHC 6.10)

David Menendez dave at
Wed Sep 24 17:32:10 EDT 2008

On Wed, Sep 24, 2008 at 5:18 PM, Jonathan Cast
<jonathanccast at> wrote:
> Right.  I (of course) take the global view as axiomatic, and I view
> Haskell 98's implementation something like this:
> If an instance is defined (somewhere in existence), then it should be in
> scope everywhere.  This is indistinguishable, in practice, from being in
> scope everywhere the class and type are both in scope.  However,
> implementing this would require the implementation to search *every*
> module with an orphan instance when looking for instances.
> (Conceptually, this should include all of Hackage; if you use an
> instance from a package, but nothing else, under --make (or -e or -i)
> that package should (in principle) still be found and linked in.)
> Presumably, it's easier to only search the modules you've imported for
> instances.  So a compromise is adopted: modules imported (directly or
> indirectly) have to be searched, but other modules can safely be
> ignored.
> So I view refusing to import one module so you can define/import a
> conflicting instance as deliberate exploitation of a
> mis-feature/limitation of the language.

Another reason to prefer the global interpretation of instances is
that it allows for more efficient, non-dictionary-passing
implementations of type classes. Both JHC's type-case and Mark Jones's
partial evaluation techniques require instances that are the same

Dave Menendez <dave at>

More information about the Libraries mailing list