vault backup: 2023-09-05 15:36:43
This commit is contained in:
@ -81,7 +81,7 @@ _: int = 4 (*same things but with another method*)
|
||||
# let average(a,b) = (a+b)/2 ;;
|
||||
val average: int*int -> int = <fun>
|
||||
|
||||
(*This method is not for several parameter, is just a one parameter wich is a couple*)
|
||||
(*This method is not for several parameter, is just a one parameter wich is a couple*) (*f(x,y) ≠ f x y*)
|
||||
|
||||
(*The OCaml way (the way that it work) *)
|
||||
# let average a b = (a+b)/2;;
|
||||
@ -89,3 +89,4 @@ val average: int -> int -> int = <fun>
|
||||
# average (-2) (2);;
|
||||
-: int = 0
|
||||
```
|
||||
|
||||
|
18
Algo/Séminaire/Chapter 3 - Case analysis.md
Normal file
18
Algo/Séminaire/Chapter 3 - Case analysis.md
Normal file
@ -0,0 +1,18 @@
|
||||
## 3.1. The alternative
|
||||
|
||||
### The if structure
|
||||
```Ocaml
|
||||
if cond then expr1 else expr2
|
||||
```
|
||||
> ⚠️ `expr1` and `expr2` have to be the same type. `cond` is a `bool`
|
||||
|
||||
**For exemple**
|
||||
```Ocaml
|
||||
# if 1<2 then "higher" else "lower" ;;
|
||||
-: string = "higher"
|
||||
|
||||
# let abs(x) =
|
||||
if x>0 then x
|
||||
else then x=x+(-x)+(-x) ;;;
|
||||
|
||||
```
|
Reference in New Issue
Block a user