MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16488.41762.711651.270386 at soggy.deldotd.com> Date: Mon, 29 Mar 2004 14:28:50 -0800 To: Jacques Garrigue Cc: lablgtk at kaba.or.jp Subject: Re: event variant types In-Reply-To: <20040329172014U.garrigue at kurims.kyoto-u.ac.jp> References: <16487.13929.266175.311338 at soggy.deldotd.com> <20040329112224Z.garrigue@kurims.kyoto-u.ac.jp> <16487.52466.85193.17461@soggy.deldotd.com> <20040329172014U.garrigue@kurims.kyoto-u.ac.jp> From: briand at aracnet.com >>>>> "Jacques" == Jacques Garrigue writes: Jacques> From: briand@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 Jacques> This is a FAQ: your definition of p1 breaks the value Jacques> restriction, and as a result the function is no longer Jacques> polymorphic. If you try to apply it to two events of Jacques> different types, you get an error. Just keep p1 outside of Jacques> your function. OK - I think I found this in the FAQ, is it : My program is not polymorphic (enough)? I'm still unclear on how the introduction of p1 "forces" event to be monomorphic, but I'll think harder :-) Thank You very much for your help. Brian