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.

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 (12:40) From: Jacques Garrigue Subject: Re: [Caml-list] Recursive Variant problem..
```> From: Charles Bouillaguet <Charles.Bouillaguet@crans.org>
> > 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

> The trouble is that the array case takes 'sort as a parameter, meaning
> that we would need an infinity of such duplicates.
> Here is the second problem: by nature, polymorphic variants only allow
> regular types (that can be represented by a regular graph), and your
> definitions do not represent a regular type (you can get ever deeper
> arrays.)

Note that this can be solved by introducing a nominal type (record or
sum type) that breaks the irregular cycles. Here the following is
sufficient.

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: 'sort; desc:
[ `Inert of unit
| `FieldRead of [`Object] base_value * 'sort field
'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

Probably this is not you wanted, but just to make things clear.

Jacques Garrigue

```