SML# Document Version 4.1.0
19 Expressions

19.6 Field selector expression #lab

A field selector is the field selection primitive function of the following type:

[’a#{lab:’b}, ’b. ’a -> ’b]

This type indicates a polymorphic function that takes a record that contains at least lab field of type ’b and returns a value of type ’b. From this type, it is clear that a record field selector can be applied to various record expressions that contains the specific label. The following shows an example:

# #y;
val it = fn : [’a#{y: ’b}, ’b. ’a -> ’b]
# #y x = 1, y = 2;
val it = 2 : int
# fun YCord x = #y x;
val YCord = fn : [’a#{y: ’b}, ’b. ’a -> ’b]
# #2;
val it = fn : [’a#{2: ’b}, ’b. ’a -> ’b]
# #2 (1,2,3);
val it = 2 : int

A tuple type is a special case of record types and therefore a record field selector is also applicable to tuples.