SML# Document Version 4.1.0
19 Expressions

19.2 Constantsscon

Constant expressions (scon) are constant literals of types intwordrealstringchar defined in Section 17.2. Among them, literals of intword,and real are overloaded, and their types are determined by their context. If there is no contextual type restriction, then they have the predefined default type.

class possible types the default type
int intint32int64int8int16intInf int
word wordword32word64word8word16 word
real realreal32 real

Constant literals string and char have string type and char type, respectively.

These constant literals evaluate to the corresponding values determined in the underlying architecture. The details of atomic value representations are defined in Chapter 29.

The following are simple examples involving overloaded constants.

# val one = 1;
val one = 1 : int
# val oneIntInf = 1 : intInf;
val oneIntInf = 1 : intInf
# fun fact 0 = oneIntInf
>   | fact n = n * fact (n - 1);
val fact = fn : intInf -> intInf
# fact 30;
val it = 265252859812191058636308480000000 : intInf
# 0w100;
val it = 0wx64 : word
# "smlsharp";
val it = "smlsharp" : string
# #"S";
val it = #"S" : char
# 3.141592;
val it = 3.141592 : real