From a61d373d4c8a6950bbb5b14d49aa966b8cd20dca Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 7 Sep 2023 16:26:16 +0200 Subject: [PATCH] vault backup: 2023-09-07 16:26:16 --- Algo/Séminaire/Chapter 3 - Case analysis.md | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Algo/Séminaire/Chapter 3 - Case analysis.md b/Algo/Séminaire/Chapter 3 - Case analysis.md index e6304c1..45a7e0a 100644 --- a/Algo/Séminaire/Chapter 3 - Case analysis.md +++ b/Algo/Séminaire/Chapter 3 - Case analysis.md @@ -68,9 +68,34 @@ match expr with pattern1 -> result1 | pattern2 -> result2 | ... | patternn -> re # let f x = match x with 0 -> 18 | 1 -> 24 - | y -> y + y;; + | y -> y * y;; val f : int -> int = # f 1;; - : int = 24 + +# let g x = match x with + 0 -> 18 + | y -> y + y (*here will return a warning : unused case*) + | 1 -> 24 ;; + +val f : int -> int = +# f 1;; +- : int = 1 + +# let d x = match x with + 0 -> 18; + | 1 -> 24;; + (* Warning = pattern matching not exhaustive *) +``` + +### Filtering several values + +```Ocaml +# let and_ a b = + match a with + true -> match b with + true -> true + | false -> false + | false -> false;; \ No newline at end of file