Re: grammar for class types, reraised

From: Jerome Vouillon (
Date: Mon Jun 14 1999 - 23:30:19 MET DST

Date: Mon, 14 Jun 1999 23:30:19 +0200
From: Jerome Vouillon <>
To: Hendrik Tews <>,
Subject: Re: grammar for class types, reraised
In-Reply-To: <>; 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;;
> and
> # 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
example :
  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

-- Jérôme

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET