ocaml - Expression of different type expected -
i have following code:
type point = { x : float; y : float; z : float } type dpoint = { dx : float; dy : float; dz : float } type physical_object = { position : point; velocity : dpoint } let move p dp = {x = p.x + dp.x; y = p.y + dp.y; z = p.z + dp.z}
i getting error:
file "code.ml", line 4, characters 21-24: error: expression has type float expression expected of type int
p.x
highlighted
why this? not referencing record's fields correctly?
operator +
has type int -> int -> int
, applicable values of type int
. use +.
operator floats, (and *.
, /.
correspondingly other operations).
ocaml doesn't have operator overloading (aka ad hoc polymorphism), doesn't play type inference. however, makes code more explicit, can considered benefit.
Comments
Post a Comment