Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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-14 (12:22)
From: Charles Bouillaguet <Charles.Bouillaguet@c...>
Subject: Recursive Variant problem..
Hello Caml-List,

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

type 'a array_ = [`Array of 'a]
type base_sort = [`Int | `Float | `Object | `Array of base_sort]  (*  
arrays of arrays are OK *)
type sort = [base_sort | `Set of  
base_sort]                                  (* sets of sets are NOT OK*)

The problem appear when I want to define my values :

type 'sort array_state = 'sort * [`ArrayStateVar of string |  
`ArrayWrite of 'me  * 'sort base_value * [`Int] base_value * 'sort  
base_value] as 'me
and 'sort base_value = 'sort * [`Inert of unit | `FieldRead of  
[`Object] base_value * 'sort field | `ArrayRead of 'sort array_state  
* ('sort array_) base_value * [`Int] base_value]
and 'sort field = 'sort * [`FieldVar of string | `FieldWrite of 'me *  
[`Object] base_value * 'sort base_value] as 'me

is refused with error :
In the definition of base_value, type
[ `Int ] array_state
should be
'a array_state

I then have two questions :

a) is it possible to write that with polymorphic variants, and how ?
b) Is it possible to wrote that with Recursive modules, and how ?

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

Charles Bouillaguet
Ens de Cachan, Currently visiting MIT.