MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16051.59001.830936.263287 at karryall.dnsalias.org> Date: Sat, 3 May 2003 17:55:37 +0200 From: Olivier Andrieu To: Richard Jones Cc: lablgtk at kaba.or.jp Subject: Re: More GtkHtml questions In-Reply-To: <20030503100346.GE24136 at redhat.com> References: <20030503100346.GE24136 at redhat.com> Richard Jones [Saturday 3 May 2003] : > > How does garbage collection work in lablgtk? It looks like my object > will never get freed up. The GtkObjects are wrapped in ML custom blocks. When the ML value is garbage collected, it calls a finalization function which is gtk_object_unref. You should wrap gtk_html_new like this : ML_0(gtk_html_new, Val_GtkAny_sink) the `_sink' thing is a peculiarity of GTK reference counting mechanisms ("floating" references) and only applies to newly created objects. > Also, the type system is very confusing. I have GtkHtml which is > derived in this hierarchy: > > Widget > -> Container > -> Layout > -> GtkHtml > > so now I'm defining: > > type html = [widget|`container|`layout|`html] > > (These variant types are very much at the edge of my experience with > OCaml - the manual is very unhelpful when it comes to explaining > exactly what the ` backquote is all about). > > Is this correct? Yes. In fact since there is already a layout type defined (in gtk.ml), you could even write : type html = [layout|`html] which is the same as : type html = [`base|`widget|`container|`layout|`html] The backquote is the syntax for polymorphic variants constructors. For a regular variant it is : type foo = BAR | BAZ and for the polymorphic versions : type foo = [`BAR | `BAZ] But mind that these types are only used as parameters for the (abstract) type Gtk.obj. These are phantom types : there are no actual values, the constructor `layout is never used to create a value, it only appears in type expressions. The point is to benefit of the subtyping relations between these polymorphic variant types. For instance, functions wrapping the GtkLayout methods take as first argument a [>`layout] obj , that means any obj with at least the `layout type. Thus all GtkLayout functions can be applied to html obj since html "extends" the layout type. > Now to define my class: > > class html obj = object > inherit GPack.layout (obj : GtkHtml.html obj) > end > > Except this doesn't actually work. I get: > > File "gHtml.ml", line 40, characters 24-27: > This expression has type GtkHtml.html Gtk.obj but is here used with type > Gtk.layout Gtk.obj > Type GtkHtml.html = [ `base | `container | `html | `layout | `widget] > is not compatible with type > Gtk.layout = [ `base | `container | `layout | `widget] > > Ideas? see Jun explanation. This change is already done in lablgtk2. -- Olivier