Version française
Home     About     Download     Resources     Contact us    
Browse thread
recursive polymorphic variants?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] recursive polymorphic variants?
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