(* Exchange the first elements of two lists *) let exchangeFirst (l1, l2) = match l1 with [] -> (l1, l2) | head1::tail1 -> (match l2 with [] -> (l1, l2) | head2::tail2 -> (head2::tail1, head1::tail2)) let exchangeFirst2 (l1, l2) = match (l1, l2) with (_, []) | ([], _) -> (l1, l2) | ((h1:int)::t1, h2::t2) -> (h2::t1, h1::t2) (* Just some polymorphic type fun *) type 'a ok = OKInt of int | OKString of string | OKSomething of 'a (* doing something with boolean whatevers *) type boolsomething = True | False | Not of boolsomething | Or of boolsomething * boolsomething | And of boolsomething * boolsomething exception Not_correct let rec do_something_boolean something = match something with True -> True | False -> False | Not q -> (match do_something_boolean q with True -> False | False -> True | _ -> raise Not_correct) (* WILL NEVER HAPPEN *) | Or (p, q) -> let p2 = do_something_boolean p in let q2 = do_something_boolean q in (match (p2, q2) with (_, True) | (True, _) -> True | _ -> False) | And (p, q) -> (match (do_something_boolean p, do_something_boolean q) with (_, False) | (False, _) -> False | _ -> True) (* detect even and odd numbers *) let rec even n = if n = 0 then true else odd (n - 1) and odd n = if n = 0 then false else even (n - 1)