Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
To: caml-list@inria.fr
Subject: Re: grammar for class types, reraised
Date: Tue, 22 Jun 1999 19:00:22 +0200	[thread overview]
Message-ID: <199906221700.TAA21025@ithif20.inf.tu-dresden.de> (raw)
In-Reply-To: <19990614233019.41897@pauillac.inria.fr>

Hi,

   From: Jerome Vouillon <Jerome.Vouillon@inria.fr>
   Date: Mon, 14 Jun 1999 23:30:19 +0200
   Subject: Re: grammar for class types, reraised
   
	[...]
   
   > 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.
   
The constraints are neccessary, if one wants to work with
interface specifications, consider:

====== file types.ml =========

class type ['a, 'b] z_type = object
	(* method declarations *)
end

====== file classes.ml ========

class ['a, 'b] z_class : ['a, 'b] z_type = object
	(* method definitions *)
end

===============================

In a realistic example you get soon type constraints in the class
definition z_class between the type parameters. This is not a
problem in the code above (because the type annotation 
['a, 'b] z_type is only required to be more general), but it gets
one, if you try

====== file classes.mli =======

class ['a, 'b] z_class : ['a, 'b] : z_type

===============================

If z_class has constraints, then it does not match the more
general type z_type and the module is rejected from the compiler.

   > 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
   
   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). 

No. I only want to mix class types (not classes) and data types
in one recursion on the type level. 

A similar recursion on the value level (i.e. mixing function
definitions and classes in one recursion) is not required,
because you can already program recursions between functions and
methods in a natural way (if you only manage to declare the types).

   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

Yes. But this works only for toy examples. If you follow
this approach in a real project you would soon end up in a
situation, where every type definition takes more than 5 type
parameters (remember, that you also have to use a type variable,
for every method, which gets covariantly overridden). This way
you get an explosion of type parameters, which is not manageable.

Just a note, why I think it is so important to have these mixture
of class types and data types:

Ocaml is one of the few languages, which have inductive data
types _and_ class types. Inductive data types and recursive
functions are the natural way to program data structures. And
class types are the natural choice, if you want to model
processes or reactive systems with some black box behaivior. From
this one could hope, that it is possible to model systems in
ocaml as they occur in practice (ie. data structures, that
organize processes, where the processes itself hold complex data
structures again, which are used ... ). 

But syntactic distinction of class types and data types makes
this impossible.

Bye,

Hendrik




  parent reply	other threads:[~1999-06-22 22:05 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
1999-06-15 17:04   ` John Prevost
1999-06-22 17:00   ` Hendrik Tews [this message]
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=199906221700.TAA21025@ithif20.inf.tu-dresden.de \
    --to=tews@tcs.inf.tu-dresden.de \
    --cc=caml-list@inria.fr \
    /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