vault backup: 2023-09-11 23:41:53
This commit is contained in:
@ -133,6 +133,8 @@ val f : int -> int = <fun>
|
||||
# let succ x = x +1;;
|
||||
val succ: int -> int = <fun>
|
||||
|
||||
(* these two functions are equivalent *)
|
||||
|
||||
# let succ = function x -> x + 1;;
|
||||
val succ: int -> int = <fun>
|
||||
```
|
||||
@ -151,7 +153,7 @@ val avg : int -> int -> int = <fun>
|
||||
|
||||
**For the match function**
|
||||
```Ocaml
|
||||
# let f x = watch x with
|
||||
# let f x = match x with
|
||||
| 0 -> 18
|
||||
| 1 -> 24
|
||||
| _ -> x*x ;;
|
||||
|
@ -1,4 +1,5 @@
|
||||
## Exercise 2.2 (Power)
|
||||
|
||||
|## Exercise 2.2 (Power)
|
||||
|
||||
```Ocaml
|
||||
(*First version ; 6 multiplications*)
|
||||
@ -213,5 +214,23 @@ let price w (p1, p2, p3, p4) =
|
||||
val price = int -> 'a * 'a * 'a * 'a -> 'a = <fun>
|
||||
```
|
||||
|
||||
## Exercise 3.9
|
||||
```Ocaml
|
||||
let apm = function
|
||||
| (0, 0) -> 2
|
||||
| (0, y) -> 1
|
||||
| (x, 0) -> 1
|
||||
| (x, y) -> 0
|
||||
| _ -> invalid_arg "Error";;
|
||||
|
||||
let strange = function
|
||||
| (0, n) -> 0
|
||||
| (m, 0) -> 2*m
|
||||
| (m, n) -> m*n ;;
|
||||
|
||||
let or3 = function
|
||||
| (a, false, false) -> "premier a"
|
||||
| (false, b, false) -> "b"
|
||||
| (false, false, c) -> "c" ;;
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user