vault backup: 2023-09-07 21:25:19

This commit is contained in:
2023-09-07 21:25:19 +02:00
parent a61d373d4c
commit 1e0b99b364
3 changed files with 44 additions and 15 deletions

View File

@ -95,7 +95,37 @@ val f : int -> int = <fun>
```Ocaml
# let and_ a b =
match a with
true -> match b with
true -> (match b with
true -> true
| false -> false
| false -> false;;
| 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