Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] troubles with polymorphic variant in class
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: nakata keiko <keiko@k...>
Subject: Re: [Caml-list] troubles with polymorphic variant in class
I hope this would be of some help.

module type Ct = sig type t end

module type Crec =
  sig
    module T : Ct
    class button : object method add_child : T.t -> unit end
  end

module COt(Crec : Crec) = 
  struct type t = [`Whatever|`Button of Crec.button] 
  end

module CO(Crec : Crec) =
  struct
    module T = COt(Crec)
    class button =
      object
        val mutable children : T.t list = [`Whatever]
        method add_child x = children <- x::children
      end
  end
module rec X : (Crec with module T = COt(X)) = CO(X)

As I done, you can specify the type of elements of the list "children"
inside "COt".
The above code is taken from 
http://caml.inria.fr/archives/200403/msg00344.html

with best regards.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners