On 08-Nov-1999, Simon Peyton-Jones <[EMAIL PROTECTED]> wrote:
> [someone wrote:]
> | I wonder why it was hard in GHC?
>
> It wasn't hard.
We're currently in the process of implementing existential types
in Mercury. Whenever we make a change, we record how long (roughly)
we think it took us to make that change. I went back over the cvs logs
of our changes to add existential types, and found that there were
about 280 hours worth of changes that were related to the addition of
existential types. And we still have more work to do before it is
finished. I'd guess we'll clock up at least another 20 hours
(maybe lots more, if we decide to add more functionality).
Supporting existential types in Mercury poses some additional difficulties
that don't occur in Haskell, due to the interaction between existential
types and Mercury's modes and mode reordering. Supporting existential types
properly turned out to require changing the ordering of the passes
in the compiler front-end, which was quite difficult, because there were
lots of places in the compiler which depended on the old ordering
in ways that the type checker can't catch.
But there were a number of other issues which could have occurred
if Mercury were just a functional language, rather than a combined
logic/functional language:
* Supporting existential quantifiers on the types for functions
required changes to the code for inlining and specialization,
because when you inline and specialize code, this may bind
type variables in the callee rather than just binding type
variables in the caller.
* Supporting existential qualifiers inside data types requires
significant extensions to our RTTI (run-time type information)
support. [These are still not yet implemented.]
Here's a break-down of that 280 hours:
Supporting the basics of existentially typed functions took
about 80 hours. (The first prototype version took only about
20 hours, but more work was required before it was sufficiently
complete, stable, and well-documented to include in our main cvs
branch.)
Adding support for mixing existential types and type classes
was a little bit more, but that wasn't too difficult.
About 20 hours at a very rough guess.
Adding support for mixing existential types and mode reordering
was quite hard indeed. About 120 hours at a rough guess.
Supporting existential data types (rather than existential quantifiers
on functions) was not as difficult as handling mode reordering, but
was still a quite substantial amount of work. About 80 hours at a
very rough guess [the work is not yet complete].
For comparison, implementing type classes took about 600 hours.
(But most of the work for type classes was done by someone who at the
time was a less experienced programmer, so those two numbers
can't really be compared directly.)
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.