Browse thread
Recursive Variant problem..
-
Charles Bouillaguet
- Stephane Glondu
-
Jacques Garrigue
- Jacques Garrigue
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jacques Garrigue <garrigue@m...> |
| 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
| `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
Probably this is not you wanted, but just to make things clear.
Jacques Garrigue