Typecasting in SML

Dave picture Dave · Jan 24, 2012 · Viewed 13.5k times · Source

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?

Answer

sepp2k picture sepp2k · Jan 24, 2012

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.