rescript-compiler
rescript-compiler copied to clipboard
Experiment with first-class dicts.
Works for this:
type myDict = {name?:string, anyOtherField?: int}
let tst = (d: myDict) => switch d {
| {name:n, something:i} => String.length(n) + i
| {name:n} => String.length(n)
| {something:i} => i
| _ => 0
}
Already works for creation and lookup, with no further changes, somehow, as long as type annotations : dict are added:
type myDict = {name?:string, anyOtherField?: int}
let tst1 = (d: myDict) => d.something
let d: myDict = {name: "hello", something: 5}
This also works as long as anyOtherField is declared mutable:
type myDict = {name?:string, mutable anyOtherField?: int}
let tst1 = (d: myDict) => d.something = Some(10)
Closing and keeping it around under the "experiment" label as discussed.