From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA09524; Tue, 2 Apr 2002 22:49:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA10831 for caml-list@pauillac.inria.fr; Tue, 2 Apr 2002 22:49:20 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA06121 for ; Tue, 2 Apr 2002 19:14:53 +0200 (MET DST) Received: from laurie.fmf.uni-lj.si (laurie.fmf.uni-lj.si [193.2.67.203]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g32HElr26329 for ; Tue, 2 Apr 2002 19:14:52 +0200 (MET DST) Received: from andrej by laurie.fmf.uni-lj.si with local (Exim 3.35 #1 (Debian)) id 16sRs2-0002zl-00; Tue, 02 Apr 2002 19:14:58 +0200 To: Attila Kondacs Cc: caml-list@inria.fr Subject: Re: [Caml-list] native-code and byte-code compiler differences References: Reply-To: Andrej Bauer From: Andrej Bauer Date: 02 Apr 2002 19:14:55 +0200 In-Reply-To: Attila Kondacs's message of "Fri, 29 Mar 2002 16:00:41 -0500 (EST)" Message-ID: User-Agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.4 (Common Lisp) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Attila Kondacs writes: > here is the code: > ... > > let map_keyboard = fun ?(mouse_action = (fun () -> ())) charactionlist -> > let st = ref true in > while !st = true do > if mouse_action != (fun () -> ()) > then (if (try button_down() with Graphic_failure _ > -> (open_graph ""; button_down ())) > then mouse_action ()); > if key_pressed() > then (match read_key() with > | 'q' -> > begin > ((find_char_action_pair charactionlist 'q' )()); > st := false > end > | a -> ((find_char_action_pair charactionlist a )())); > done;; Ignoring the fact that this is a very bad way to wait for an event, I am very much puzzled by the line that says if mouse_action != (fun () -> ()) You are performing a physical inequality test on functions. I am sure you do not want to do this. (Beware: in ocaml there are = and <>, and there are == and !=. Make sure you know which is which.) Consider the following example: Objective Caml version 3.04 # (fun () -> ()) != (fun () -> ());; - : bool = true So, fun () -> () and fun () -> () are not equal, since they are two closures located in different parts of memory. Presumably, your program wil never execute the 'else' part of the outermost 'if then else' statement, because mouse_action != (fun () -> ()) will always evaluate to true. It's not clear to me how your program could work at all. You should never compare functions. Do you think this should evaluate to true: (fun x -> x + x) = (fun x -> 2 * x) How about this? (fun x -> x + 0) = (fun x -> x + 1 - 1) In general, comparison of functions is not decidable. Physical equality test (are two functions the same piece of code?) can be done, but is _usually_ not what you want. However, I am unable to come up with an example that uses != on functions and behaves differently when compiled with ocamlc and ocamlopt. Can anyone help? Andrej ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners