To: briand at aracnet.com Cc: lablgtk at kaba.or.jp Subject: Re: event variant types In-Reply-To: <16487.52466.85193.17461 at soggy.deldotd.com> References: <16487.13929.266175.311338 at soggy.deldotd.com> <20040329112224Z.garrigue@kurims.kyoto-u.ac.jp> <16487.52466.85193.17461@soggy.deldotd.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20040329172014U.garrigue at kurims.kyoto-u.ac.jp> Date: Mon, 29 Mar 2004 17:20:14 +0900 From: Jacques Garrigue Lines: 30 From: briand at aracnet.com > However when I try to establish p1 as a closure variable : > > let draw_polyline_interactively = > let p1 = ref { x=0.; y=0.; z=0. } in > fun area drawv event -> > let event = (event :> GdkEvent.any) in > ... > > I get an error at the _calling_ location (not in the function declaration) : > > This expression has type GdkEvent.Button.t = GdkEvent.Button.types Gdk.event > but is here used with type > GdkEvent.Key.t = [ `KEY_PRESS | `KEY_RELEASE ] Gdk.event > Type > GdkEvent.Button.types = > [ `BUTTON_PRESS > | `BUTTON_RELEASE > | `THREE_BUTTON_PRESS > | `TWO_BUTTON_PRESS ] > is not compatible with type [ `KEY_PRESS | `KEY_RELEASE ] > These two variant types have no intersection This is a FAQ: your definition of p1 breaks the value restriction, and as a result the function is no longer polymorphic. If you try to apply it to two events of different types, you get an error. Just keep p1 outside of your function. Jacques