In-Reply-To: <16486.17988.561211.516751 at soggy.deldotd.com> References: <16483.50834.898498.682875 at soggy.deldotd.com> <16483.63571.455639.187324@akasha.ijm.jussieu.fr> <16486.17988.561211.516751@soggy.deldotd.com> Subject: Re: event variant types To: briand at aracnet.com Cc: lablgtk at kaba.or.jp Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040328191235E.garrigue at kurims.kyoto-u.ac.jp> Date: Sun, 28 Mar 2004 19:12:35 +0900 From: Jacques Garrigue Lines: 26 From: briand at aracnet.com > I've created a simpler test program. > > here is some relevant code: > > let handle_event event = > match GdkEvent.get_type event with > (* #GdkEvent.Button.types -> handle_button_event event; true *) > `KEY_PRESS -> Printf.printf "key press\n"; true > | `MOTION_NOTIFY -> Printf.printf "motion\n"; true > | _ -> false Sorry, using variant polymorphism can get tricky if you want to keep type safety. There are two solutions: * either replace "_" by "#Gdk.Tags.event_type" in the above * or add the following line at the beginning of handle_event let event = (event :> GdkEvent.any) in This is the most robust solution, as it will work even if you change handle_event. You can of course add the same coercion at calls of handle_event, but this is less clean. Jacques