From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D365ABCA2 for ; Thu, 18 Aug 2005 23:50:46 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j7ILokab029001 for ; Thu, 18 Aug 2005 23:50:46 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA12419 for ; Thu, 18 Aug 2005 23:50:45 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7ILohlP022088 for ; Thu, 18 Aug 2005 23:50:45 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j7ILod7H006264; Fri, 19 Aug 2005 06:50:40 +0900 (JST) Date: Fri, 19 Aug 2005 06:51:18 +0900 (JST) Message-Id: <20050819.065118.03980029.garrigue@math.nagoya-u.ac.jp> To: nr@eecs.harvard.edu Cc: caml-list@inria.fr Subject: Re: [Caml-list] recursive polymorphic variants? From: Jacques Garrigue In-Reply-To: <20050818212744.94BD41EB0C3@labrador.eecs.harvard.edu> References: <20050818212744.94BD41EB0C3@labrador.eecs.harvard.edu> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 430502B6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 430502B3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 recursive:01 variants:01 variants:01 hashtbl:01 compiler:01 recursive:01 abstracting:01 reuse:01 cvs:01 ocaml:01 unnamed:98 polymorphic:01 polymorphic:01 extensible:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: nr@eecs.harvard.edu (Norman Ramsey) > 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 type > 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 http://www.math.nagoya-u.ac.jp/~garrigue/papers/ 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. Jacques Garrigue