ocaml.org icon indicating copy to clipboard operation
ocaml.org copied to clipboard

Add text on nested or pattern

Open cuihtlauac opened this issue 1 year ago • 4 comments

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

cuihtlauac avatar Jan 19 '24 16:01 cuihtlauac

Interesting. Does it suffice, if we add this in the https://ocaml.org/docs/basic-data-types#a-complete-example-mathematical-expressions sub-section?

The-Amoghavarsha avatar Jan 23 '24 09:01 The-Amoghavarsha

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.

cuihtlauac avatar Jan 23 '24 10:01 cuihtlauac

Maybe we should do a whole document on advanced pattern matching

  • This
  • Combined patterns, expressions with several data types
  • as patterns
  • when patterns
  • stacked/fallback patterns
  • exceptions patterns

cuihtlauac avatar Feb 12 '24 09:02 cuihtlauac

Yes, I think this goes beyond the scope of Basic Data Types and Pattern-Matching and having a separate document would be great!

sabine avatar Feb 12 '24 09:02 sabine