Re: why here a int and not a float ?
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
> I try to learn Ocaml by following the Ocaml from the very beginning. > > I have to write a function that multiplies a number by 10. > > So I did : let multiply_ten x = x * 10 ;; > > but to my surprise I see that the function has this : val multiply_ten : int -> int = <fun> > > How can I change it so I can also calculate 2.5 * 10 ? Ocaml strictly distinguishes between floats and ints. That means you have to explicitly convert from one to the other. It even uses different arithmetic operators: * : int * int -> int *. : float *. float -> float You can convert between float/int by float : int -> float truncate : float -> int These functions might help, too: ceil : float -> float floor : float -> float see here http://www.csc.villanova.edu/~dmatusze/resources/ocaml/ocaml.html#intops for example. r. [Non-text portions of this message have been removed]