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 AAA02890; Mon, 5 Aug 2002 00:56:57 +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 AAA02531 for caml-list@pauillac.inria.fr; Mon, 5 Aug 2002 00:56:57 +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 JAA27757 for ; Sun, 4 Aug 2002 09:55:21 +0200 (MET DST) Received: from kraid.nerim.net (kraid.nerim.net [62.4.16.95]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g747tK519985 for ; Sun, 4 Aug 2002 09:55:20 +0200 (MET DST) Received: from chinon (jmarant.net1.nerim.net [62.212.105.6]) by kraid.nerim.net (Postfix) with ESMTP id 9841D4102E for ; Sun, 4 Aug 2002 09:46:06 +0200 (CEST) Received: by chinon (Postfix, from userid 1000) id 4395680C671; Sun, 4 Aug 2002 09:53:22 +0200 (CEST) To: caml-list@inria.fr Subject: Re: [Caml-list] Using %identity for casting types References: <20020802154858.A18074@fr.thalesgroup.com> <20020802232931I.garrigue@kurims.kyoto-u.ac.jp> From: jmarant@nerim.net (=?iso-8859-1?q?J=E9r=F4me?= Marant) Date: Sun, 04 Aug 2002 09:53:22 +0200 In-Reply-To: <20020802232931I.garrigue@kurims.kyoto-u.ac.jp> (Jacques Garrigue's message of "Fri, 02 Aug 2002 23:29:31 +0900") Message-ID: <87u1mbukjx.fsf@marant.org> User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jacques Garrigue writes: > Well, not really, but if you're interfacing with C++, it's not more > dangerous to do the cast in ocaml than in C++ (except if you use > rtti). > > The above idiom is equivalent to > > let unsafe_cast : 'a obj -> 'b obj = Obj.magic > > It may be more efficient, as the compiler knows that unsafe_cast is > the identity, and can discard it. No code is generated. > > I also tend to prefer it because it makes clear the need to properly > write types: such casts only make sense at a precise type, while > Obj.magic is 'a -> 'b, which allows too much. > > And, as always, only use unsafe casts for non-ocaml data. > Ocaml datatypes are expressive enough that you don't need unsafe > casts for them. Thanks a lot. Cheers, -- Jérôme Marant http://marant.org ------------------- 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