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 TAA26164; Wed, 15 Oct 2003 19:03:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA25477 for ; Wed, 15 Oct 2003 19:03:30 +0200 (MET DST) Received: from mwinf0104.wanadoo.fr (smtp1.wanadoo.fr [193.252.22.30]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9FH3T123723 for ; Wed, 15 Oct 2003 19:03:29 +0200 (MET DST) Received: from debian (ca-bordeaux-12-69.w80-8.abo.wanadoo.fr [80.8.84.69]) by mwinf0104.wanadoo.fr (SMTP Server) with ESMTP id B295A1B40641 for ; Wed, 15 Oct 2003 19:03:29 +0200 (CEST) Received: from moi by debian with local (Exim 3.36 #1 (Debian)) id 1A9p3h-0002Cj-00 for ; Wed, 15 Oct 2003 19:03:37 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] NaN-safe min and max References: <18220.141.155.88.179.1066229526.squirrel@minsky-primus.homeip.net> From: Remi Vanicat Mail-Copy-To: never Date: Wed, 15 Oct 2003 19:03:36 +0200 In-Reply-To: <18220.141.155.88.179.1066229526.squirrel@minsky-primus.homeip.net> (Yaron Minsky's message of "Wed, 15 Oct 2003 10:52:06 -0400 (EDT)") Message-ID: <87u16a77rr.dlv@wanadoo.fr> User-Agent: Gnus/5.090024 (Oort Gnus v0.24) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 yaron:01 minsky:01 yminsky:01 cornell:01 andrieu:01 pervasives:01 val:01 0.0:01 val:01 abstr:01 abstr:01 bool:01 bool:01 unsafe:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk "Yaron Minsky" writes: > Olivier Andrieu proposed the following code for doing a safe min/max. > Does anyone have any thoughts about this code snippet, and whether it is > or is not a safe use of Obj.magic? > > let min a b = > let o = Obj.repr a in > if Obj.is_block o && Obj.tag o = Obj.double_tag > then Obj.magic (fmin (Obj.magic a) (Obj.magic b)) > else Pervasives.min a b this one is unsafe : the fact that a is a block with a tag Obj.double_tag doesn't proof that the same is true for b even if a and b have the same type : # let i1 = Lazy.lazy_from_val 0.0;; val i1 : float Lazy.t = lazy 0. # let o1 = Obj.repr i1;; val o1 : Obj.t = # Obj.is_block o1;; - : bool = true # Obj.tag o1 = Obj.double_tag;; - : bool = true # let i2 = lazy 3;; val i2 : int lazy_t = # let o2 = Obj.repr i2;; val o2 : Obj.t = # Obj.is_block o2;; - : bool = true # Obj.tag o2 = Obj.double_tag;; - : bool = false both i1 and i2 have the same type, but only the first one is a block of tag Obj.double_tag. A verification have to be done for both argument. -- Rémi Vanicat remi.vanicat@laposte.net ------------------- 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