|
|
|
|
|
by andrepd
2015 days ago
|
|
Tbf I find infix operators much more straightforward and readable. E.g.: let file = file |? raise Some_error
or let parse_result = parse <$> file
For the last two examples respectively.EDIT: For completeness, the operators are let (|?) opt y =
match opt with
| Some x -> x
| None -> y
let (<$>) f opt =
match opt with
| Some x -> Some (f x)
| None -> None
|
|
I imagine the possible ways of handling non-nullable types (and algebraic types as a whole) as a spectrum:
* TS style explicit if branches: Easy for beginners, annoying to experts
* Rust style methods on Option/Result/etc: Slightly confusing for beginners, somewhat elegant for experts
* Haskell/OCaml style infix operators: Confusing for beginners, elegant and easy for experts
Note that this is beginners to functional programming. Not necessarily beginners in programming as a whole. Plenty of smart people would get tripped up by a `<$>`