vault backup: 2023-09-07 16:08:59
This commit is contained in:
@ -49,3 +49,28 @@ Exception: Invalid_argument "oops"
|
||||
else a/b ;;;
|
||||
val div int -> int -> int = <fun>
|
||||
```
|
||||
|
||||
## 3.3. Filtering
|
||||
### Explicit filtering
|
||||
|
||||
> Explicit means that you matches the value
|
||||
|
||||
|
||||
**General syntax**
|
||||
|
||||
```Ocaml
|
||||
match expr with pattern1 -> result1 | pattern2 -> result2 | ... | patternn -> resultn
|
||||
```
|
||||
> All expressions and pattern must avec the same type
|
||||
|
||||
**Example**
|
||||
```Ocaml
|
||||
# let f x = match x with
|
||||
0 -> 18
|
||||
1 -> 24
|
||||
y -> y + y;;
|
||||
|
||||
val f : int -> int = <fun>
|
||||
|
||||
# f 1;;
|
||||
- : int = 24
|
||||
|
Reference in New Issue
Block a user