2 ms·
Incedentally, OCaml gets some of these right. Record update in constructors is statically checked: type myData = MyData1 of { name : string } | MyData2 of
by more_original 10y ago
Incedentally, OCaml gets some of these right.
Record update in constructors is statically checked:
type myData = MyData1 of { name : string } | MyData2 of { value : int }
let x = MyData1 { name = "hello" }
(*
* rejected:
* let y = MyData2 { x with value = 0 }
*)
let y = match x with
| MyData1 z -> failwith "todo"
| MyData2 z -> MyData2 { z with value = 0 }
And one can write:
match x with
| A | B -> f1
| C -> f2