Skip to main content

Type conversion

Types can be converted to more precise types automatically when no precision loss occurs. This is called upcasting.

Upcast for numbers

For instance, if a function expects an int but receives a byte, then the byte is automatically converted to an int:

let f(v: int) = ...
in f(1b) // 1b is a byte of value 1, but converted to int as needed by f

For numbers, the upcast order is that byte -> short -> int -> long -> float -> double -> decimal. That is, a long can be converted to a float, double or decimal as needed, while a double can only be converted to a decimal.

Upcast for temporals

A date can also be converted to a timestamp, where the time component of the timestamp is set to zero.