Extensible records now appear in the dev-branch of Elm, so if you sync to the latest version of the compiler on github you can try it out :)
I am pretty excited about this! The paper linked above gives a formal overview, but the syntax in Elm will be a bit different for readability and to avoid some syntactic ambiguities. Here's a general overview of the syntax in Elm (light blue text shows how the expressions are evaluated):
Defining Records. Fields can be polymorphic functions. No need for type signatures or ADTs, just create the record and the types are inferred:
empty = {}
point = { x = 3, y = 4 }
book = { title = "Steppenwolf"
, author = "Hermann Hesse" }
group1 = { op x y = x + y
, zero = 0 }
group2 = { op x y = x ++ y
, zero = [] }
Deleting fields (restriction):
{ point - x } == { y = 4 }
{ book - author } == { title = "Stepenwolf" }
Adding fields (extension):
{ point | z = 12 } == { x = 3, y = 4, z = 12 }
{ book | pages = 150 } == { title = "Steppenwolf", author = "Hermann Hesse", pages = 150 }
Renaming fields:
{ book - title | name = book.title } == { name = "Steppenwolf", author = "Hermann Hesse" }
Replacing values (you can change the type of a field too!):
{ book - title | title = True } == { title = True, author = "Hermann Hesse" }
Prettier and more concise way to replace values. This allows you to batch changes too:
{ point | x <- 0 } == { x = 0, y = 4 }
{ book | title <- "Das Glasperlenspiel" }
{ book | title <- "Harry Potter"
, author <- "J. K. Rowling" }
(vx,vy) = (10,10)
t = 1
{ point | x <- point.x + vx * t
, y <- point.y + vy * t } == { x = 13, y = 14 }
You can also do some pattern matching on records when used in function definitions and let-expressions. You can be selective about what fields to access, so it's okay to pattern match on a record with extra fields:
dist {x,y} = sqrt (x^2 + y^2)
dist point == dist { x = 3, y = 4, z = 12 }
Finally you can use arbitrary field accessors. The type of the accessor is inferred from its name and can be used on any record that has that field:
map .author books
map .x points
That's pretty much everything for now! If you give it a try tell me what you think while things are still flexible.
Warning: There is something odd going on with the type-checker, so some type-errors with records don't get caught at the moment. I am hoping to do a general rewrite of the type-checking code to clean up the code and resolve this kind of issue.
Enjoy!
Evan