Records (Base Types)

types
basetypes

#1

The following examples show records and their types.

val r1 = @{x = "flat record", y = 2.0} : @{x = string, y = double}
val r2 = '{x = "boxed record", y = true}: '{x = string, y = bool}
val r3 = $rec{x = "boxed record", y = 42}: '{x = string, y = int}

And you can use it as follows.

val @{x = m, y = n} = r1
val _ = println! (m, n)

val '{x = m, ...} = r3
val _ = println! m 

val $rec(y = n, ...) = r2
val _ = println! n

@{} is for flat records. '{} and $rec{} is for boxed records. We can use ... to mean we don’t care about the rest of records.

Notice that there is one line where $rec() is used, weird.


Documentation Catalog