From 4ca90c0f38ca45e63a3521601fc436de4d031a91 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 5 Sep 2023 15:36:43 +0200 Subject: [PATCH] vault backup: 2023-09-05 15:36:43 --- .obsidian/workspace.json | 11 ++++++----- Algo/Séminaire/Chapter 2 - Functions.md | 3 ++- Algo/Séminaire/Chapter 3 - Case analysis.md | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 Algo/Séminaire/Chapter 3 - Case analysis.md diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 1e8cdf1..ed35cf8 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -13,7 +13,7 @@ "state": { "type": "markdown", "state": { - "file": "Algo/Séminaire/Chapter 2 - Functions.md", + "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", "mode": "source", "source": false } @@ -85,7 +85,7 @@ "state": { "type": "backlink", "state": { - "file": "Algo/Séminaire/Chapter 2 - Functions.md", + "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -102,7 +102,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "Algo/Séminaire/Chapter 2 - Functions.md", + "file": "Algo/Séminaire/Chapter 3 - Case analysis.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -125,7 +125,7 @@ "state": { "type": "outline", "state": { - "file": "Algo/Séminaire/Chapter 2 - Functions.md" + "file": "Algo/Séminaire/Chapter 3 - Case analysis.md" } } } @@ -148,10 +148,11 @@ }, "active": "13c9bfe482ec2d42", "lastOpenFiles": [ + "Algo/Séminaire/Chapter 2 - Functions.md", + "Algo/Séminaire/Chapter 3 - Case analysis.md", "Algo/Séminaire/Exercices sémaines.md", "Algo/Séminaire/assets/69E2987C-209A-48CD-8964-5A60462966E5.jpg", "Algo/Séminaire/Chapter 1 - CAML basics.md", - "Algo/Séminaire/Chapter 2 - Functions.md", "Algo/Séminaire/Introduction.md", "Algo/Séminaire/assets", "Algo/Séminaire/assets/F1D2AA19-E790-4022-AFFF-F778EAB28AB5.jpg", diff --git a/Algo/Séminaire/Chapter 2 - Functions.md b/Algo/Séminaire/Chapter 2 - Functions.md index 61901df..2136c70 100644 --- a/Algo/Séminaire/Chapter 2 - Functions.md +++ b/Algo/Séminaire/Chapter 2 - Functions.md @@ -81,7 +81,7 @@ _: int = 4 (*same things but with another method*) # let average(a,b) = (a+b)/2 ;; val average: int*int -> int = -(*This method is not for several parameter, is just a one parameter wich is a couple*) +(*This method is not for several parameter, is just a one parameter wich is a couple*) (*f(x,y) ≠ f x y*) (*The OCaml way (the way that it work) *) # let average a b = (a+b)/2;; @@ -89,3 +89,4 @@ val average: int -> int -> int = # average (-2) (2);; -: int = 0 ``` + diff --git a/Algo/Séminaire/Chapter 3 - Case analysis.md b/Algo/Séminaire/Chapter 3 - Case analysis.md new file mode 100644 index 0000000..7c9f6bf --- /dev/null +++ b/Algo/Séminaire/Chapter 3 - Case analysis.md @@ -0,0 +1,18 @@ +## 3.1. The alternative + +### The if structure +```Ocaml +if cond then expr1 else expr2 +``` +> ⚠️ `expr1` and `expr2` have to be the same type. `cond` is a `bool` + +**For exemple** +```Ocaml +# if 1<2 then "higher" else "lower" ;; +-: string = "higher" + +# let abs(x) = + if x>0 then x + else then x=x+(-x)+(-x) ;;; + +```