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 LAA04729; Tue, 1 Oct 2002 11:45:26 +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 LAA04806 for ; Tue, 1 Oct 2002 11:45:26 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g919is509656; Tue, 1 Oct 2002 11:44:54 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA04964; Tue, 1 Oct 2002 11:44:54 +0200 (MET DST) Date: Tue, 1 Oct 2002 11:44:54 +0200 From: Xavier Leroy To: Chris Hecker Cc: caml-list@inria.fr Subject: Re: [Caml-list] float tuples as double_arrays? Message-ID: <20021001114454.E3571@pauillac.inria.fr> References: <4.3.2.7.2.20020927192452.02e6b520@mail.d6.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <4.3.2.7.2.20020927192452.02e6b520@mail.d6.com>; from checker@d6.com on Fri, Sep 27, 2002 at 07:34:45PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > The floats in an all-float tuple are boxed, unlike floats in all-float > records. The latter are treated as float arrays internally and have > double_array_tag. I'm wondering why the former aren't treated the same > way? Complexity in the compiler and not wanting the double_array special > case code to metastasize more is a perfectly valid answer. I agree with the answer you suggest :-) Another reason is that, unlike records statically declared with "float" fields only, tuples can be used polymorphically: a float * float can be passed to a function expecting an 'a * 'b. This would require run-time tests in polymorphic functions operating over tuples. Similar tests are already generated for polymorphic functions operating on arrays, but the tests for tuples would be more complex because tuples, unlike arrays, are not homogeneous: one run-time test on one component doesn't suffice to determine the type of all other components. > The only reason I ask is that the unboxed rep is more efficient, and tuples > are more convenient for some things, like breaking things out with patterns: > [...] > or with a record > let {x=x;y=y;z=z;} = v in > (* need the module name on the field above if not opened, etc. *) This is true. Despite this, I still recommend the use of records, even if they are syntactically a bit heavier than tuples: you get the "dot notation" (e.g. v.x, v.y, v.z in your example above), and finer type distinctions if you need them (e.g. you might want to have different types for 3D point and 3D vectors, for additional type safety). - Xavier Leroy ------------------- 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