To: briand at aracnet.com Cc: lablgtk at kaba.or.jp Subject: Re: event variant types In-Reply-To: <16482.33127.497203.821118 at soggy.deldotd.com> References: <16482.33127.497203.821118 at soggy.deldotd.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040325165247V.garrigue at kurims.kyoto-u.ac.jp> Date: Thu, 25 Mar 2004 16:52:47 +0900 From: Jacques Garrigue Lines: 45 From: briand at aracnet.com > So I tried a type which looks like : > > type an_event = E1 of GdkEvent.Motion.t | E2 of GdkEvent.Key.t | E3 of GdkEvent.Button.t ;; > > and a match which looks like > > let multi_event_procedure drawv event = > ... > match event with > E1(event) -> true > | E2(event) -> true > | E3(event) -> true; > > which is in a routine which is invoked : > > area#event#add [`BUTTON_PRESS]; > w#event#connect#button_press ~callback: > begin fun ev -> > multi_event_procedure drawv ev; > true > end; > > which gives me the error : > > This expression has type GdkEvent.Button.t = GdkEvent.Button.types Gdk.event > but is here used with type an_event This is not surprising: if you use an event wrapped with a variant, then you must first wrap it: multi_event_procedure drawv (E3 ev); But I have a strange feeling that is not what you are actually trying to do. The point is, all events are already part of the GdkEvent.any type. So you don't have to wrap anything. If you want to distinguish some specific events, you can do it with GdkEvent.get_type: match GdkEvent.get_type event with #GdkEvent.Button.types -> true | #GdkEvent.Key.types -> true | #GdkEvent.Motion.types -> true | _ -> false for instance. Jacques