
-----------------------------------
wtd
Wed Aug 11, 2004 7:11 pm

[O'Caml-tip] This is seriously cool
-----------------------------------
Just piced this one up from comp.lang.functional.

Let's say I want to copy a structure, but want to change one member.

For starters, the structure describes a point in three-dimensions.

type point3d = { x : int; y : int; z : int }

Now I define one point:

let first_point = { x = 1; y = 6; z = 42 }

Now I want to copy the first point into a second point, but zero the z coordinate.  The lengthy (and thus more error-prone) method is:

let second_point = {x = first_point.x; y = first_point.y; z = 0 }

Instead, how about...

let second_point = { first_point with z = 0 }
