19.2 Constantsscon
Constant expressions (scon) are constant literals of types int, word, real, string, char defined in Section 17.2. Among them, literals of int,word,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 | int,int32,int64,int8,int16,intInf | int |
word | word,word32,word64,word8,word16 | word |
real | real,real32 | 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