Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
To: Hendrik Tews <tews@tcs.inf.tu-dresden.de>, caml-list@inria.fr
Subject: Re: grammar for class types, reraised
Date: Mon, 14 Jun 1999 23:30:19 +0200	[thread overview]
Message-ID: <19990614233019.41897@pauillac.inria.fr> (raw)
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;;
> 
> 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
    and
    type b = Node of a | Tree of b * b
into
    type 'a b = Node of 'a | Tree of b * b
    class type a = object method m : a b end

-- Jérôme




  reply	other threads:[~1999-06-15  0:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-14  8:04 Hendrik Tews
1999-06-14 21:30 ` Jerome Vouillon [this message]
1999-06-15 17:04   ` John Prevost
1999-06-22 17:00   ` Hendrik Tews
1999-06-23  1:40     ` Jacques GARRIGUE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19990614233019.41897@pauillac.inria.fr \
    --to=jerome.vouillon@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=tews@tcs.inf.tu-dresden.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox