vault backup: 2023-09-07 16:26:16
This commit is contained in:
@ -68,9 +68,34 @@ match expr with pattern1 -> result1 | pattern2 -> result2 | ... | patternn -> re
|
|||||||
# let f x = match x with
|
# let f x = match x with
|
||||||
0 -> 18
|
0 -> 18
|
||||||
| 1 -> 24
|
| 1 -> 24
|
||||||
| y -> y + y;;
|
| y -> y * y;;
|
||||||
|
|
||||||
val f : int -> int = <fun>
|
val f : int -> int = <fun>
|
||||||
|
|
||||||
# f 1;;
|
# f 1;;
|
||||||
- : int = 24
|
- : int = 24
|
||||||
|
|
||||||
|
# let g x = match x with
|
||||||
|
0 -> 18
|
||||||
|
| y -> y + y (*here will return a warning : unused case*)
|
||||||
|
| 1 -> 24 ;;
|
||||||
|
|
||||||
|
val f : int -> int = <fun>
|
||||||
|
# f 1;;
|
||||||
|
- : int = 1
|
||||||
|
|
||||||
|
# let d x = match x with
|
||||||
|
0 -> 18;
|
||||||
|
| 1 -> 24;;
|
||||||
|
(* Warning = pattern matching not exhaustive *)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Filtering several values
|
||||||
|
|
||||||
|
```Ocaml
|
||||||
|
# let and_ a b =
|
||||||
|
match a with
|
||||||
|
true -> match b with
|
||||||
|
true -> true
|
||||||
|
| false -> false
|
||||||
|
| false -> false;;
|
Reference in New Issue
Block a user