Existential types: want better syntactic support (autoboxing?)
waldmann at imn.htwk-leipzig.de
Mon Jan 30 04:05:51 EST 2006
Cale Gibbard wrote:
> How do we decide which constructor to apply, or even which existential
> type is desired?
By giving a type declaration. - I guess you criticize this because then,
writing a type declaration would change the meaning of the program.
You know in Java I write, e. g. Component c = new Button ("foobar");
essentially hiding that c is a Button,
and only telling that it will be used as a Component.
So we have in fact a distinction between the type of the object
and the type of a name that refers to it. (Of course both must be
related.) From an engineering standpoint, this is nice as it can be
used to enforce information hiding.
How can we achieve the same effect in Haskell?
> Perhaps you disagree? :) I'm not exactly sure what kind of design
> you're thinking of where it's so inconvenient to apply the constructor
> by hand that it would warrant this kind of change to the language --
The inconvenience is not so much in writing the constructor:
I also have to invent its name and write out its definition somewhere.
> perhaps you could give an example. :)
Button/Component, LinkedList/List etc. I know you asked for Haskell
examples: I will give them as soon as there are libraries that contain
them :-) I think current libraries do not use this idea (existentials)
much because there is no syntactical support .. quoting Wittgenstein,
[5.6] Die Grenzen meiner Sprache bedeuten die Grenze meiner Welt.
(The limits of my language mean the limits of my world.)
PS: by my count, a lot of the typecasts in Java programs come from using
the pre-1.5 collections framework. But that's been fixed meanwhile, and
it has nothing to do with the above discussion of information hiding.
-- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
---- http://www.imn.htwk-leipzig.de/~waldmann/ -------
More information about the Haskell-prime