[Haskell-cafe] resolving missing class instances @ compile time

Samuel Bronson naesten at gmail.com
Thu May 12 17:37:39 EDT 2005

On 12/05/05, Greg Buchholz <haskell at sleepingsquirrel.org> wrote:
> Samuel Bronson wrote:
> > After thinking about it for a while, I'm positive it would be a LOT of
> > work to get that to work in general, if it is even possible. Even
> > getting it to work in only specific, limited cases (such as within a
> > module) would probably not be easy, since it is such an indirect kind
> > of thing. It probably wouldn't be all that usefull anyway, either.
>     (This is my last time, I promise).  Why?  Here's my thought process.
> Let's say I a have a program like...
>     main = print $ (foo 42)
> ...(that's the whole thing).  The compiler parses it, determines that
> "foo" is a function being applied to "42" and tries to look up "foo" in
> the symbol table.  That fails because there is no function "foo".  Why
> is it any different if foo is part of some type class?  We must know
> where to look for "foo" since we know the type of "foo" from its
> arguments and return value (it passed the type checker after all).

Well, it would have to know that foo was being applied to 42 at
whatever type it was being applied at (Might be Int), and it would
also have to know that the instance declaration for foo's typeclass at
that type did bind foo. Now this might not sound so bad, but consider
the case where you call a function bar :: Foo a => a -> String, which
is not part of the typeclass but is defined in another module. Then
GHC would have to know which methods of Foo were implemented at
whatever type the value you applied bar to had, and which methods bar
actually called. The former may not be hard, but the latter would
require functions with typeclass constraints on their types to be
annotated in the interface file with what typeclass methods they
called. Does that sound hard yet?

More information about the Haskell-Cafe mailing list