instance export decls

Serge D. Mechveliani mechvel at botik.ru
Tue Apr 22 08:32:44 EDT 2008


Dear GHC developers, people,

Do you agree that there exists such a problem for a programmer as 
recalling exported instances?
Have Haskell and/or GHC some constructs and tools to help the programmer 
to recall the exported instances for a module? 
Could GHC support the instance export messages for each module?

In Haskell-98, the exported instances cannot be named explicitly in the
export list.
Right?
But for easier understanding of a program, it is desirable to allow to 
name (in a short form) instances in the export list. 
For this reason, I add comments, and write the export like this:

  module Poly 
  (WithHead(..), WithTail(..), -- classes
   Mon(..), Polynomial(..),
   lc, polMons
   -- , instances
   -- for Mon:         WithHead, List;
   -- for Polynomial:  WithHead, Cast Polynomial Mon  
  )
The comment of kind  "-- , instances ..."   
helps to recall which instances are exported, without inspecting all 
the (lengthy) module source. 

But when the programmer changes the source, one often forgets to 
add/remove the needed comments about instances.
I often forget them (maybe, lazy to recall) when I move pieces of code 
between modules.

So, I suggest the following feature for GHC.

1. To allow the export declarations of kind   instance {<type>}
   (maybe to suggest this for Haskell ?)
2. If the module under compilation has the word `instance' in its 
   export list,  
   then  ghc  finds the difference set  diff  for the exported instance 
   kinds  eKinds  and the instance kinds  nKinds  named in the export
   list. If  not $ null diff,  it issues the message:
   "Warning:  the exported instance kinds and the instance kinds named 
              in the export differ in the following items: ...".

Seeing such a message, the user corrects the export list in the source 
according to  diff.

For the export list and for their messages, it is probably better to 
use a short denotation: the instance kind rather than full instance 
declaration. In the instance kind, the part of "(...) =>" is skipped.

What people think of this suggestion?

Thank you in advance for your notes and help,

-----------------
Serge Mechveliani
mechvel at botik.ru




  


More information about the Glasgow-haskell-users mailing list