caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] float tuples as double_arrays?
@ 2002-09-28  2:34 Chris Hecker
  2002-10-01  9:44 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Hecker @ 2002-09-28  2:34 UTC (permalink / raw)
  To: caml-list


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.

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:

let x,y,z = v in
(* use x y z here *)

while with an array you'd have

let [|x;y;z;|] = v in
(* this generates an incomplete match warning because the size isn't typed *)

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. *)

Chris

-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] float tuples as double_arrays?
  2002-09-28  2:34 [Caml-list] float tuples as double_arrays? Chris Hecker
@ 2002-10-01  9:44 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2002-10-01  9:44 UTC (permalink / raw)
  To: Chris Hecker; +Cc: caml-list

> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-01  9:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-28  2:34 [Caml-list] float tuples as double_arrays? Chris Hecker
2002-10-01  9:44 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).