English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Recursive Variant problem..
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-05-15 (08:07)
From: Stephane Glondu <glondu@c...>
Subject: Re: [Caml-list] Recursive Variant problem..
Charles Bouillaguet wrote:
> I would like to write a type which describe some kind of term in a toy 
> programming language. It has sets, but not sets of sets
> [...]
> a) is it possible to write that with polymorphic variants, and how ?
> b) Is it possible to wrote that with Recursive modules, and how ?

It reminds me of the following:

** Norman Ramsey asked and Jacques Garrigue answered:

  > I'm trying to write a small, extensible interpreter, and I'd like to
  > use polymorphic variants as the extension mechanism.  But I'm getting
  > stuck on very simple things.  For example, I would like the value
  > to include a few simple values, but I would also like it to be
  > extensible, thus:
  >   type value = [ `Nil
  >                | `Number   of float
  >                | `String   of string
  >                | `Function of [>value] list -> [>value]
  >                | `Table    of ([>value], [>value]) Hashtbl.t
  >                ]
  > However, when I do this, the compiler complains that
  >   The type constructor value is not yet completely defined
  > Is there some way to define a recursive, *extensible* type using
  > polymorphic variants?

Have a look at "Private rows: abstracting the unnamed" and
"Code reuse through polymorphic variants" at

They both give examples of how to define extensible languages using
polymorphic variants. The first one relies on an experimental feature
only available in the CVS version of ocaml.


I haven't read the papers yet, so I cannot go further.

> I'm CC-ing my classmate Romain (Hi, Romain !), as he may be interested...

And what about me? :-(

Stephane Glondu
ENS de Cachan, currently visiting Keio Universty (Tokyo)