From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA06247 for caml-red; Mon, 5 Feb 2001 17:57:21 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA11088 for ; Mon, 5 Feb 2001 04:05:28 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f1535Mr29686 for ; Mon, 5 Feb 2001 04:05:23 +0100 (MET) Received: from localhost (mikan.kurims.kyoto-u.ac.jp [130.54.16.202]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id MAA27963; Mon, 5 Feb 2001 12:05:06 +0900 (JST) To: mattias@fforum.se Cc: caml-list@inria.fr Subject: Re: Typing problems when using LablGTK In-Reply-To: <200102032154.f13LsK116451@fforum.se> References: <200102032154.f13LsK116451@fforum.se> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010205120505T.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 05 Feb 2001 12:05:05 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: weis@pauillac.inria.fr Hello Mattias, > The first program works fine, but if I take the let button-part and > move it to a separate function called mini, the compilation fails. > The type of the method attach is different. > > What have I misunderstood? Your problem is explained in the tutorial (1st part of the reference manual) in section 2.1.3. To be correctly handled, labeled and optionals arguments need to be known at the application point. If you move this application out of its context, the type information is lost, and an incorrect type is inferred. The standard solution is to add a type annotation on objects whose methods have optional arguments: let mini (table : GPack.table) = GButton.button ~label:"mini" ~packing:(table#attach ~left:3 ~top:3 ~expand:`BOTH) (); () > /mattias > > P.s. I learning GNOME using the book "Beginning GTK+/GNOME > Programming", and sometimes it is difficult to map GTK in C to > LablGTK. I am on page 111. While the relation is kept intuitive, there are indeed differences between GTK and LablGTK. Otherwise you wouldn't be able to write much shorter programs :-) If you really don't know how to translate, the low-level interface gives access to the raw calls, but this is much less comfortable. > Program 2, fails > ================ > > open GMain > > let mini table : unit = > GButton.button ~label:"mini" > ~packing:(table#attach ~left:3 ~top:3 ~expand:`BOTH) (); > () > > > let main () = > let window = GWindow.window ~border_width:10 ~title:"Fun with tables" ~width:320 ~height:200 () in > window#connect#destroy ~callback:Main.quit; > let table = GPack.table ~rows:10 ~columns:10 ~packing:window#add () in > mini table; > window#show (); > Main.main () > > let _ = Printexc.print main ()