Date: Mon, 14 Jun 1999 23:30:19 +0200
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: Hendrik Tews <email@example.com>, firstname.lastname@example.org
Subject: Re: grammar for class types, reraised
In-Reply-To: <199906140804.KAA01028@ithif20.inf.tu-dresden.de>; from Hendrik Tews on Mon, Jun 14, 1999 at 10:04:32AM +0200
On Mon, Jun 14, 1999 at 10:04:32AM +0200, Hendrik Tews wrote:
> 1. What is the difference between
> # class type b = [int, string] a;;
> # type c = (int, string) a;;
> assuming some class type a with two type parameters?
The former expression also defines a class type and a type #c.
> And why do I have to use different parentheses in both cases?
> (Yes, I know, it's what the manual says, but I would expect that
> one kind of parentheses should be enough for all kind of type
> parameters. )
It was not possible to use regular parentheses for class parameters,
as the grammar would have been too hard to parse. Consider for
class d = (a b : t)
class d = (a b) d
On the other hand, it was not acceptable to change the grammar of
types. That's why there are two different kind of parenthesis.
> 2. Why is it not possible to add type constraints to the first
> kind of type abbreviation, like in
> class type ['a] c = ['a, string] a constraint 'a = int;;
There is no real reason. I think I could add this quite easily to the
language if you need this.
> 3. (To re-raise a question from John Prevost which has never been
> addressed:) Why is it not possible to mix type definitions and
> class type definitions like in
> # class type a = object method m : a end
> # and
> # type b = Node of a | Tree of b * b
> (Yes, it is possible to use the < ... > notation, but it is not
> possible to use # with such types.)
This would probably be possible, but it is not trivial. And then, you
would probably expect to be able to include in the recursion other
construct, such as value definitions (for instance, if a function
using the type b is used by the class a). This would make the
implementation even more complicated.
On the other hand, you can get rid of the mutual recursion by adding a
type parameter to one of the type. For instance, you can change
class type a = object method m : b end
type b = Node of a | Tree of b * b
type 'a b = Node of 'a | Tree of b * b
class type a = object method m : a b end
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET