caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* record field access
@ 2006-10-21  3:53 j.romildo
  2006-10-21  7:23 ` [Caml-list] " Jon Harrop
  0 siblings, 1 reply; 3+ messages in thread
From: j.romildo @ 2006-10-21  3:53 UTC (permalink / raw)
  To: caml-list

Hello.

Regarding performance, is there any difference in accessing a record
field using pattern matching and using the dot notation?

For instance, given the declarations,

   type point = { x: float; y: float }

   let sqr x = x *. x

   let dist1 p q =
      sqrt (sqr (q.x -. p.x) +. sqr (q.y -. p.y))

   let dist2 {x=x1; y = y1} {x=x2; y=y2} =
      sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))

what should be preferable: dist1 or dist2?

And to compare records with tuples, given also

   let dist3 (x1,y1) (x2,y2) =
      sqrt (sqr (x2 -. x1) +. sqr (y2 -. y1))

what should be preferable: dist2 or dist3, regarding performance?

Romildo


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

end of thread, other threads:[~2006-10-21 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-21  3:53 record field access j.romildo
2006-10-21  7:23 ` [Caml-list] " Jon Harrop
2006-10-21 14:07   ` Christophe Raffalli

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