vault backup: 2023-10-27 14:35:01
This commit is contained in:
@ -57,3 +57,21 @@ val exists: (bool -> bool) -> bool list -> bool = <fun>
|
||||
```
|
||||
|
||||
## Ex 2.5
|
||||
```Ocaml
|
||||
# let rec filter p : function
|
||||
| [] -> []
|
||||
| e::t -> if p e then
|
||||
e::filter p t
|
||||
else filter p t;;
|
||||
val filter: ('a -> bool) -> 'a list -> 'a
|
||||
```
|
||||
|
||||
## Ex 2.6
|
||||
```Ocaml
|
||||
let rec partition p l =
|
||||
match l with
|
||||
| [] -> ([], [])
|
||||
| h==t> let (l1, l2) = partition p t in
|
||||
if p h then (h::l1,l2)
|
||||
else (l1, h::l2);;
|
||||
val partition : ('a -> bool) -> 'a list -> 'a list * 'a list = <fun>
|
Reference in New Issue
Block a user