instance visibility

Claus Reinke claus.reinke at talk21.com
Fri Sep 26 13:44:09 EDT 2008


> Sigh.  I'm not having much luck convincing you, so let me try a 

And there I thought the goal of this discussion was to reach a 
common understanding, not to convince anyone of anything..

> different tack.  Here's a scenario I'd like your opinion on:
> 
> We have a test in GHC's test suite called instance-leak, which tests 
> that none of the Haskell 98 libraries exports the Functor instance for 
> (->).  I broke this test recently by accident.  How did I break it?  By 
> using Data.Map internally in System.Process.  The Functor instance for 
> (->) is exported from Control.Monad.Instances, makes its way into 
> Data.Map, then into System.Process and thereby into System, which is a 
> Haskell 98 module.
> 
> In your opinion, who or what is at fault for this test failure?  

You, of course:-p 

But seriously: I can't see easily how the instance even gets into 
Data.Map, but since Data.Map doesn't seem to be using either
Functor or fmap (other than defining an instance itself), it has no 
business importing (and thus re-exporting) the instance. If it is
actually using any of the other instances (is it?), then perhaps
Control.Monad.Instances needs to be split up.

That is the approach taken for Data.Generics.Instances, which 
also has no business being imported in Data.Map.

Btw, it would be useful to have a tool for tracing instances
(not just final export and original definition, but the import
path in between). And it would be useful to see exported
instances for each module in Haddock (not just alongside
class and type).

> Think carefully about the ramifications of your answer.  

That was my quick answer. Do you think it will change?-)

Claus




More information about the Libraries mailing list