Is this intended to work or are record shorthands only for writing functions that only return a record field?
printCustomer = "Hello \(.name) \(.lastName)!"
My understanding was that this takes a record and prints its fields name and lastName, but that doesn't work.
I don't think this is expected to work for a few reasons.
you would need to write something like:
printCustomer = \c -> "Hello \(c.name) \(c.lastName)!"
The .field
syntax is simply a way to implicitly generate an accessor lambda. This gives you something you could pass into another function.
It enables things like:
List.map customers .name
or more generally:
doSomething = \data, getName ->
name = getName data
# do some stuff and return something
# calling it
doSomething myCustomer .name
so really .name
just translates to \x -> x.name
Ah, got it, thank you for the examples :-)
Last updated: Jul 06 2025 at 12:14 UTC