I'm new to SML, and am using the SMLNJ dialect.
For some purpose I have been trying to typecast 3 to 3.0 (int to real).
Could not find a way out. How can I do this? How can I convert between types?
We write lists as a sequence of integers, separated by commas, all enclosed with two square brackets. So then we have valid int lists as [1, 2, 3] , [1, 5, 1, 5, 0] , and [] , with the latter representing the empty list. We also refer to the empty list as nil (in addition, you can type nil instead of [] in code).
Functions in SML We can declare a function with the fun keyword. fun fact (0 : int) : int = 1 | fact (n : int) : int = n * fact (n - 1) The above example serves to initialize a function that computes the factorial function, and then bind it to the identifier fact .
You can use the function real
(or Real.fromInt
) to convert an int
to a real
.
For further information you can see a list of functions available in the Top-level environment here and an overview of the Basis library here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With