Records that fit any shape
title_of asks for a title and nothing
more. A Task works, an inline record works, and a
record without a title is a compile error.
types
Task = { id: Int, title: String }
functions
// `| rest` lets any other fields through
title_of(r: { title: String | rest }) -> String {
r.title
}
main() {
let task: Task = { id: 1, title: "Write docs" }
Log.info(title_of(task))
Log.info(title_of({ title: "Ship it", author: "Ann" }))
}
$ polar run records.px
Write docs
Ship it