You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are examples of how to get and update records (and their "desugared" versions)
readA = \record -> record |>.a# readA = \record -> record.awriteA = \value -> \record -> record |> &a value
# writeA = \value -> \record -> { record & a: value }
This one works
readT = \type -> \record ->
record
|>when type isA -> .aB -> .bC -> .c# readT = \type -> \record -># when type is# A -> record.a# B -> record.b# C -> record.cexpect (readT A) { a: "Roc", b: "is", c: "great" } =="Roc"
But the next one isn't valid
writeT = \type, value -> \record ->
record
|>when type isA -> &a value
B -> &b value
C -> &c value
# writeT = \type, value -> \record -># when type is# A -> { record & a: value }# B -> { record & b: value }# C -> { record & c: value }expect (writeT C"the best") { a: "Roc", b: "is", c: "great" } == { a: "Roc", b: "is", c: "the best" }
It's a silly example but I think the point is understood.
The text was updated successfully, but these errors were encountered:
@ricardo-valero this is a good first issue if you are interested exploring further.
The record update is parsed into roc_parse::ast::Expr::RecordUpdater and then de-sugared in crates/compiler/can/src/desugar.rs. It's pretty much all contained to one pattern match in desugar_expr, and a fun place to see how the front end of the compiler AST is handled.
These are examples of how to get and update records (and their "desugared" versions)
This one works
But the next one isn't valid
It's a silly example but I think the point is understood.
The text was updated successfully, but these errors were encountered: