Re: why here a int and not a float ?

"Robert Jakob [email protected] [ocaml_beginners]" <[email protected]>
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]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.