Understanding extensible records

You don’t really need to define types, you could write getFooName as:

getFooName : { r | name : String } -> String
getFooName foo =
    foo.name

and it would work with any record with a name : String field.

But actually there is already a syntax for such functions in the language itself, check in elm repl:

> .name
<function> : { b | name : a } -> a

So .name is exactly that, and uses extensible records. You can use foo.name or .name foo.

> .name { name = "foo" }
"foo" : String

> { name = "foo" }.name
"foo" : String
1 Like