ocaml.org
ocaml.org copied to clipboard
Add text on nested or pattern
This is valid OCaml:
# function Ok Either.(Left x | Right x) -> Some x | Error _ -> None;;
- : (('a, 'a) Either.t, 'b) result -> 'a option = <fun>
# let any (Either.Left x | Either.Right x) = x;;
val any : ('a, 'a) Either.t -> 'a = <fun>
It should be mentioned in the Basic Data Types and Pattern-Matching tutorial. Thanks @chshersh for point this
Interesting. Does it suffice, if we add this in the https://ocaml.org/docs/basic-data-types#a-complete-example-mathematical-expressions sub-section?
It would be nice to have text about this there. But a section on nested matching is needed. We'd also discuss matching on several types; it will include the above but won't be limited to it.
Maybe we should do a whole document on advanced pattern matching
- This
- Combined patterns, expressions with several data types
aspatternswhenpatterns- stacked/fallback patterns
- exceptions patterns
Yes, I think this goes beyond the scope of Basic Data Types and Pattern-Matching and having a separate document would be great!