RE: why here a int and not a float ?
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
To: [email protected] From: [email protected] Date: Sun, 22 Feb 2015 12:35:18 +0100 Subject: Re: "ocaml_beginners"::[] why here a int and not a float ? > 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] I know that and according to the page you linked to * is Always a int. But my question stays. How can I tell Ocaml when I make a function that it has to use floats instead of int. Roelof