let foo f (a,b) c = (a^"" , f a + b);;
let foo f g x = f x + g (x+1);;
let rec length l acc = match l with [] -> acc | hd::tl -> length tl (acc +1);;
let rec f l = match l with [] -> true | hd::[] -> true | hd1::hd2::tl -> if (hd1>hd2) then false else f (hd2::tl);;
let rec flatten l = match l with [] -> [] | hd::tl -> hd @ flatten tl;;
let rec nth n l = match l with [] -> failwith "Lista troppo corta" | hd::tl -> if n = 1 then hd else nth (n-1) tl;;
'inteRevert
' inverte le cifre di un interolet intRevert n = if n < 10 then n else let rec intrev n acc = if n=0 then acc else let resto = n mod 10 in let cifra = acc*10 + resto in intrev (n/10) cifra in intrev n 0 ;; let ispalindrome n = (n = intRevert n);;
Alternativa con utilizzo delle liste: 'intToList
' trasforma un intero nella lista delle sue cifre
let rec intToList n = if n < 10 then [n] else let cifra = n mod 10 in (listaCifreRec (n / 10)) @[cifra] ;;
'reverse
' inverte una lista
let reverse l = let rec reverse' l acc = match l with [] -> acc | hd::tl -> reverse' tl acc@[hd] in reverse' l [];;
let ispalindrome n = let l = intToList n in l = reverse l;;