Version française
Home     About     Download     Resources     Contact us    
Browse thread
recursive records with weak hashtbl
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Virgile Prevosto <virgile.prevosto@m...>
Subject: Re: [Caml-list] recursive records with weak hashtbl
Hello,

Le mer. 04 mars 2009 16:31:02 CET,
Vsevolod Fedorov <sevaAtWork@mail.ru> a écrit :

> type a
> {
>   id : int ;
>   mutable field1 : string;
>   mutable b : B;
> }
> type b
> {
>     id : int;
>     mutable field2 : string;
>     a_list : Weak-Hashtbl(a);  (* they referenced me *)
> }
> 
> Is it possible at all?

mutually recursive types are defined like this:
type a = { ... } 
and b = { ... }

> Is it possible with A and B declarations in separate files?

not directly, but you can use a polymorphic type to break the recursion.
Assuming that a is defined in a.ml and b in b.ml and that a.ml depends
upon b.ml, you'd have:
- b.ml -
type 'a b = { ... a_list: 'a Weak.t }
- a.ml -
type a = { ... mutable b: a B.b }

BTW, I'd say that such a topic would be better on the ocaml beginners
list (see reference below)

Regards,
-- 
E tutto per oggi, a la prossima volta.
Virgile