I am not understanding why I am getting this error: Unbound record field mid_x when running this code. What the function midpoint_segment is trying to do is find the midpoint of a given type segment and return a point type.
type point =
{x : float; y : float}
type segment =
{startp : point; endp : point}
let midpoint_segment {startp; endp} =
let mid_x = (startp.x +. endp.x) /. 2.0 in
let mid_y = (startp.y +. endp.y) /. 2.0 in
{mid_x; mid_y}
What does this error mean? I am defining mid_x and mix_y with let.
{mid_x; mid_y}is syntax sugar for the record literal{mid_x = mid_x; mid_y = mid_y}.If you want to create a record of type
pointyou either need to specify the record field labels explicitly:{x = mid_x; y = mid_y}or, to use field punning, renamemid_xandmid_ytoxandyin order to do{x; y}.