Version française
Home     About     Download     Resources     Contact us    
Browse thread
mutually dependent class and type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yann_Régis-Gianas <yann.regis-gianas@i...>
Subject: Re: [Caml-list] mutually dependent class and type
Hello Sebastien,

you can use recursive module:

module rec I : sig
  class element : I.content ->  object end
  type content =
    | Data of string
    | Elements of I.element list
end = struct
  class element (c : I.content) = object end
  type content =
    | Data of string
    | Elements of I.element list
end

Best regards,

-- 
Yann Régis-Gianas



On Fri, Sep 26, 2008 at 12:24 AM, Sébastien Hinderer
<Sebastien.Hinderer@ens-lyon.org> wrote:
> Dear list,
>
> Is there a (clean) way to define simultaneously a class and a type that
> are mutually recursive ?
> Something like this :
> class element (c : content) =
> object
>  ...
> end and type content =
>  | Data of string
>  | Elements of element list;;
>
> This is of course not a valid OCaml definition, but is there a way to
> express it ?
>
> Many thanks in advance for your help,
> Sébastien.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>