From 1e0b99b364f2c6c3844658dc724eec90af9847bf Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 7 Sep 2023 21:25:19 +0200 Subject: [PATCH] vault backup: 2023-09-07 21:25:19 --- .obsidian/workspace.json | 14 ++++---- Algo/Séminaire/Chapter 3 - Case analysis.md | 36 +++++++++++++++++++-- Algo/Séminaire/Introduction.md | 9 +++--- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index a9309f7..4e4b1df 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -13,7 +13,7 @@ "state": { "type": "markdown", "state": { - "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", + "file": "Algo/Séminaire/Chapter 1 - CAML basics.md", "mode": "source", "source": false } @@ -85,7 +85,7 @@ "state": { "type": "backlink", "state": { - "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", + "file": "Algo/Séminaire/Chapter 1 - CAML basics.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -102,7 +102,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", + "file": "Algo/Séminaire/Chapter 1 - CAML basics.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -125,7 +125,7 @@ "state": { "type": "outline", "state": { - "file": "Algo/Séminaire/Chapter 3 - Case analysis.md" + "file": "Algo/Séminaire/Chapter 1 - CAML basics.md" } } } @@ -148,11 +148,11 @@ }, "active": "bdba25946b821d06", "lastOpenFiles": [ - "Algo/Séminaire/Exercices seminaire.md", - "Algo/Séminaire/Chapter 3 - Case analysis.md", - "Algo/Séminaire/Chapter 1 - CAML basics.md", "Algo/Séminaire/Chapter 2 - Functions.md", "Algo/Séminaire/Introduction.md", + "Algo/Séminaire/Chapter 1 - CAML basics.md", + "Algo/Séminaire/Chapter 3 - Case analysis.md", + "Algo/Séminaire/Exercices seminaire.md", "Algo/Séminaire/assets/69E2987C-209A-48CD-8964-5A60462966E5.jpg", "Algo/Séminaire/assets", "Algo/Séminaire/assets/F1D2AA19-E790-4022-AFFF-F778EAB28AB5.jpg", diff --git a/Algo/Séminaire/Chapter 3 - Case analysis.md b/Algo/Séminaire/Chapter 3 - Case analysis.md index 45a7e0a..c5358b4 100644 --- a/Algo/Séminaire/Chapter 3 - Case analysis.md +++ b/Algo/Séminaire/Chapter 3 - Case analysis.md @@ -95,7 +95,37 @@ val f : int -> int = ```Ocaml # let and_ a b = match a with - true -> match b with + true -> (match b with true -> true - | false -> false - | false -> false;; \ No newline at end of file + | false -> false) + | false -> false;; +``` + +> ⚠️ If you forgot the parentheses, Caml will belived the two `|false` belong to the same pattern matching + +### Universal pattern +```Ocaml +# let f x = match x with + 0 -> 18 + | 1 -> 24 + | _ -> x*x ;; +``` + +### "Or" filter +```Ocaml +let f x match x with + 0 | 20 -> 18 + | 1 | 11 | 12 -> 24 + |_ -> x * x ;; +``` + +### Guarded filters +```Ocaml +let sign x = match x with + 0 -> 0 + | y when y < 0 -> -1 + | _ -> 1 +``` + +> `y when y<0` is an evaluation + diff --git a/Algo/Séminaire/Introduction.md b/Algo/Séminaire/Introduction.md index 3108cab..f7e549b 100644 --- a/Algo/Séminaire/Introduction.md +++ b/Algo/Séminaire/Introduction.md @@ -4,11 +4,10 @@ - The goal is to take an input and give an output with the solution ## How to write an algorithm -1) What : - - What do you have available ; What is the output that your searching for => this is call specifications - - How : find resolution methods and choose the best one - - Formalism : shape it like a computer talk - - Translate : +1) What do you have available ; What is the output that your searching for => this is call specifications +2) How : find resolution methods and choose the best one +3) Formalism : shape it like a computer talk +4) Translate : ## Compilation and interpretation ### Compiler