vault backup: 2023-09-11 23:41:53

This commit is contained in:
Louis Gallet 2023-09-11 23:41:53 +02:00
parent 206c76bd7c
commit 38f5bd8492
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY
3 changed files with 34 additions and 5 deletions

View File

@ -11,8 +11,12 @@
"id": "00ae67f71d1252f8", "id": "00ae67f71d1252f8",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "empty", "type": "markdown",
"state": {} "state": {
"file": "Algo/Séminaire/Exercices seminaire.md",
"mode": "source",
"source": false
}
} }
} }
] ]
@ -81,6 +85,7 @@
"state": { "state": {
"type": "backlink", "type": "backlink",
"state": { "state": {
"file": "Algo/Séminaire/Exercices seminaire.md",
"collapseAll": false, "collapseAll": false,
"extraContext": false, "extraContext": false,
"sortOrder": "alphabetical", "sortOrder": "alphabetical",
@ -97,6 +102,7 @@
"state": { "state": {
"type": "outgoing-link", "type": "outgoing-link",
"state": { "state": {
"file": "Algo/Séminaire/Exercices seminaire.md",
"linksCollapsed": false, "linksCollapsed": false,
"unlinkedCollapsed": true "unlinkedCollapsed": true
} }
@ -118,7 +124,9 @@
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "outline", "type": "outline",
"state": {} "state": {
"file": "Algo/Séminaire/Exercices seminaire.md"
}
} }
} }
] ]

View File

@ -133,6 +133,8 @@ val f : int -> int = <fun>
# let succ x = x +1;; # let succ x = x +1;;
val succ: int -> int = <fun> val succ: int -> int = <fun>
(* these two functions are equivalent *)
# let succ = function x -> x + 1;; # let succ = function x -> x + 1;;
val succ: int -> int = <fun> val succ: int -> int = <fun>
``` ```
@ -151,7 +153,7 @@ val avg : int -> int -> int = <fun>
**For the match function** **For the match function**
```Ocaml ```Ocaml
# let f x = watch x with # let f x = match x with
| 0 -> 18 | 0 -> 18
| 1 -> 24 | 1 -> 24
| _ -> x*x ;; | _ -> x*x ;;

View File

@ -1,4 +1,5 @@
## Exercise 2.2 (Power)
|## Exercise 2.2 (Power)
```Ocaml ```Ocaml
(*First version ; 6 multiplications*) (*First version ; 6 multiplications*)
@ -213,5 +214,23 @@ let price w (p1, p2, p3, p4) =
val price = int -> 'a * 'a * 'a * 'a -> 'a = <fun> val price = int -> 'a * 'a * 'a * 'a -> 'a = <fun>
``` ```
## 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" ;;
```