instance export decls

Simon Peyton-Jones simonpj at microsoft.com
Thu May 1 10:21:11 EDT 2008


Indeed! I think it'd be good to allow type signatures, including instance signatures, in export lists

module Foo(
        data T (f :: * -> *),
        instance Functor f => Eq (T f),
        g :: T f -> T f
  )

The first step is to evolve a well-worked-out design. I think that'd be a very valuable thing for someone to do.  Indeed, I'd really like to see it in Haskell', but it doesn't meet the "tried and tested" criterion.

I'm a bit reluctant to invest effort in half-way-house solutions, though.

Simon


| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On
| Behalf Of Serge D. Mechveliani
| Sent: 22 April 2008 13:33
| To: glasgow-haskell-users at haskell.org
| Subject: instance export decls
|
| 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 Haskell-prime mailing list