diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 70922d9..5cb2bfd 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -11,8 +11,12 @@ "id": "00ae67f71d1252f8", "type": "leaf", "state": { - "type": "empty", - "state": {} + "type": "markdown", + "state": { + "file": "Algo/Séminaire/Exercices seminaire.md", + "mode": "source", + "source": false + } } } ] @@ -81,6 +85,7 @@ "state": { "type": "backlink", "state": { + "file": "Algo/Séminaire/Exercices seminaire.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -97,6 +102,7 @@ "state": { "type": "outgoing-link", "state": { + "file": "Algo/Séminaire/Exercices seminaire.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -118,7 +124,9 @@ "type": "leaf", "state": { "type": "outline", - "state": {} + "state": { + "file": "Algo/Séminaire/Exercices seminaire.md" + } } } ] diff --git a/Algo/Séminaire/Chapter 3 - Case analysis.md b/Algo/Séminaire/Chapter 3 - Case analysis.md index b2f3ef1..a26b836 100644 --- a/Algo/Séminaire/Chapter 3 - Case analysis.md +++ b/Algo/Séminaire/Chapter 3 - Case analysis.md @@ -133,6 +133,8 @@ val f : int -> int = # let succ x = x +1;; val succ: int -> int = +(* these two functions are equivalent *) + # let succ = function x -> x + 1;; val succ: int -> int = ``` @@ -151,7 +153,7 @@ val avg : int -> int -> int = **For the match function** ```Ocaml -# let f x = watch x with +# let f x = match x with | 0 -> 18 | 1 -> 24 | _ -> x*x ;; diff --git a/Algo/Séminaire/Exercices seminaire.md b/Algo/Séminaire/Exercices seminaire.md index cfbc7b5..0949473 100644 --- a/Algo/Séminaire/Exercices seminaire.md +++ b/Algo/Séminaire/Exercices seminaire.md @@ -1,4 +1,5 @@ -## Exercise 2.2 (Power) + +|## Exercise 2.2 (Power) ```Ocaml (*First version ; 6 multiplications*) @@ -213,5 +214,23 @@ let price w (p1, p2, p3, p4) = val price = int -> 'a * 'a * 'a * 'a -> 'a = ``` +## Exercise 3.9 +```Ocaml +let apm = function + | (0, 0) -> 2 + | (0, y) -> 1 + | (x, 0) -> 1 + | (x, y) -> 0 + | _ -> invalid_arg "Error";; +let strange = function + | (0, n) -> 0 + | (m, 0) -> 2*m + | (m, n) -> m*n ;; + +let or3 = function + | (a, false, false) -> "premier a" + | (false, b, false) -> "b" + | (false, false, c) -> "c" ;; +```