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

View File

@ -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