caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: skaller@users.sourceforge.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] extensible records again
Date: Wed, 24 Mar 2004 10:41:18 +0900	[thread overview]
Message-ID: <20040324104118K.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <1080069240.4708.39.camel@pelican.wigram>

From: skaller <skaller@users.sourceforge.net>

> At the moment you can do this:
> 
> type x = [`A | `B ]
> type y = [x | `C ]
> 
> so that y is a subtype (extension) of x.
> 
> You can even match:
> 
> match aY with
> | #x as xv -> xv
> | _ -> failwith "Not an x"
> 
> to reduce aY to an x.

[...]
Let me just add a pointer to the concrete description of how you can
do this with recursive types:
http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/fose2000.html

It describes in detail the steps to build extensible recursive
datatypes.

> In Felix, I want to partition expressions, types,
> patterns, statements, and a few other kinds of terms
> into one or more classes and use some combinations
> of these: but all these terms are mutually recursive:
> statements can contain expressions and types and patterns,
> patterns have 'when' expressions, types may contain
> "typeof(expression)" as a type, and statements can
> be considered as expressions..
> 
> So I end up with a rather large number of parameters
> on each of the fine grained components I want to combine:
> something like:
> 
> type 'expr 'typ 'pat 'stat expr1 = ....
> ...
> type 'expr 'typ 'pat 'stat typ1 = ...
> ...

The mixin2.ml code on the above page gives an example of you can do
it using classes. Note that this solves only the problem for
functions, not for types.

Another approach, which could maybe solve the problem with type
parameters, would be to use recursive modules: define all your
sublanguages as functors, and close the recursion with a recursive
module definition. Recursive modules are a new feature in ocaml 3.07,
but I think they can help for such problems.
However, there is a difficulty, as all modules in a recursive
definition must have an explicit signature, and the language of module
types seems to be weaker than the language of modules.
The fact one has to duplicate all type definitions is bothering too.

> type x = [`A of +x | `B ]
> type y = [x | `C ]

might be encoded as

module type Xrec = sig type t end
module X0(Xrec : Xrec) =
  struct type t0 = Xrec.t type t = [`A of t0 | `B] end
module type Xsig = sig type t0 type t = [`A of t0 | `B] end
module rec X : (Xsig with type t0 = X.t) = X0(X)
module Y0(Xrec : Xrec) =
  struct
    module XY = X0(Xrec)
    type t0 = Xrec.t
    type t = [XY.t | `C]
  end
module type Ysig = ???
module rec Y : (Xsig with type t0 = Y.t) = Y0(Y)

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-03-24  1:41 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-21  6:21 Michael Vanier
2004-03-21  8:08 ` Oleg Trott
2004-03-21  8:40   ` Michael Vanier
2004-03-21 16:10     ` Oleg Trott
2004-03-21 17:06       ` skaller
2004-03-21 17:36         ` Oleg Trott
2004-03-22  3:19           ` skaller
2004-03-22  7:49           ` Ville-Pertti Keinonen
2004-03-22  9:32             ` Oleg Trott
2004-03-22 10:25               ` Ville-Pertti Keinonen
2004-03-21 22:35         ` Michael Vanier
2004-03-22  3:39           ` skaller
2004-03-21 22:34       ` Michael Vanier
2004-03-22  3:31         ` skaller
2004-03-22  5:54           ` Michael Vanier
2004-03-23 19:14             ` skaller
2004-03-24  1:41               ` Jacques Garrigue [this message]
2004-03-24  8:44                 ` Julien Signoles
2004-03-24 10:04                   ` Jacques Garrigue
2004-03-21  8:53 ` Martin Jambon
2004-03-21  9:22   ` Michael Vanier
2004-03-21 17:00 ` skaller
2004-03-22  8:13 ` Achim Blumensath
2004-03-23  2:14   ` Michael Vanier
2004-03-23  7:25     ` Achim Blumensath
2004-03-31 10:05 ` Marcin 'Qrczak' Kowalczyk

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=20040324104118K.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    /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;
as well as URLs for NNTP newsgroup(s).