-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutovalutazione20221108.ml
40 lines (36 loc) · 997 Bytes
/
Autovalutazione20221108.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(* versione tail recursive *)
(* ('a * 'a) list -> 'a -> bool *)
let rec has_range_in list k =
match list with
| [] -> false
| (x,y)::rest ->
(* gli operatori di confronto possono essere applicati a qualunque tipo *)
if x<=k && k<=y
then true
else has_range_in rest k
(* ('a * 'a) list -> 'a list -> 'a list *)
let compito ranges list =
(* ('a * 'a) -> 'a -> bool *)
let in_range range input =
match range with
| a,b -> min a b <= input && input <= max a b
in
(* ('a * 'a) list -> 'a -> bool *)
let rec has_range_in range_list k =
match range_list with
| [] -> false
| (x,y)::rest ->
(* gli operatori di confronto possono essere applicati a qualunque tipo *)
if in_range (x,y) k
then true
else has_range_in rest k
in
(* 'a list -> 'a list -> 'a list *)
let rec aux tmp = function
| [] -> tmp
| x::rest ->
if has_range_in ranges x
then aux (x::tmp) rest
else aux tmp rest
in
aux [] list