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

Popular posts from this blog

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -