|
|
|
|
|
by Zababa
1652 days ago
|
|
Standard ML and OCaml have both sum types (like in Rust) and exceptions. I feel like both have their value, and both are important. A nice thing is that you can match on exceptions: match number_of_lines_of_a_file() with
| x -> x
[ exception File_not_found -> 0
This makes it really easy to create alternative versions of functions, using exceptions or option types: match number_of_lines_of_a_file_opt() with
| Some x -> x
| None -> raise File_not_found
match number_of_lines_of_a_file_exc() with
| x -> Some x
| exception File_not_found -> None
|
|