instance declarations

Mark P Jones mpj@cse.ogi.edu
Mon, 10 Dec 2001 00:33:21 -0800


Hi David,

| >Recently, however, there has been some interest in using named instance
| >declarations in other ways, so perhaps we will see features like this
| >creeping into future versions of the language.
| 
| In what kinds of ways?  Sounds interesting.

I was thinking of a couple of papers from the most recent Haskell
workshop.  See http://www.cs.uu.nl/people/ralf/hw2001.html for some
pointers (the second session).


| >  module M(C(..), instance C Int, instance C a => C [a]) where ...
| 
| This is the sort of thing I was thinking too.  But I would probably want
| to extend that to classes and types.  For instance
| 
| module M (class Eq a=>C a (...), type A, instance C A, instance C a => C
| [a])
| where ...

Yes, that's also what I had in mind at the more verbose end of the
spectrum (which is not to say that I think it would be a bad thing).
A richer, more explicit syntax for export lists might provide some
useful documentation and be easier to read than a syntax that leaves
you guessing whether C(..) refers to a type or a class.  On the other
hand, if things start to get too wordy, you might instead want to add
a separate notation for describing interfaces.  The following is an
throwaway syntax, intended only to hint at the basic idea:

  interface I where
    class C a where f :: a -> a
    instance C Int
    instance C a => C [a]

  module M implements I where ...
    ...

Start allowing parameterization and other interesting features and
this begins to look somewhat like ML style modules (and related
systems).

All the best,
Mark