Date: Mon, 4 Apr 2005 17:17:40 +1200 From: Tim Smith To: LablGTK List Subject: odd type annotation needed; why? Message-ID: <20050404051740.GB816 at siva.hindu.god> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi! I asked this question on ocaml_beginners at list, but no one was able to respond. I'm hoping someone here will know. Thanks for any answers! I have a simple program here: http://www.magnesium.net/~thim/tmp/hello3.ml If I compile it as is, it works fine. But I had to add an odd type annotation to my function, and I know why. My function is: let pack_new_button_in_box (box:GPack.box) str = let button = GButton.button ~label:str ~packing:box#pack () in ignore (button#connect#clicked ~callback:(clicked str)) I call it like: let box1 = GPack.hbox ~packing: window#add () in pack_new_button_in_box box1 "A Button"; Why do I need to force the 'box' argument to be of type GPack.box? Why can't OCaml sort that out on its own? If I change it to just 'box', then I get this error: ocamlc -verbose -I +lablgtk2 lablgtk.cma gtkInit.cmo hello3.ml -o hello3 File "hello3.ml", line 30, characters 27-31: This expression has type GPack.box but is here used with type < pack : GObj.widget -> unit; .. > Types for method pack are incompatible Thanks, Tim -- If you're not part of the solution, you're part of the precipitate.