I have recently started coding in ocaml and this programming language is hell sensible when it comes to defining what I want a function to return. I want to write a function that uses 2 lists as parameters (supposed to be in ascending order and with elements of type int) and returns a list that contains all the elements of the first 2 lists, also in ascending order.
Here is what I managed to get so far:
let inter l1 l2 =
let rec aux l1 l2 l3=
if List.hd l1<List.hd l2 then aux (List.tl l1) l2 (List.hd l1 :: l3)
else (if List.hd l1>List.hd l2 then aux l1 (List.tl l2) (List.hd l2::l3)
else (if l1 = [] then List.fold_left (fun x y -> y::x) l3 l2
else if l2=[] then List.fold_left (fun x y -> y::x) l3 l1
))
in List.rev (aux l1 l2 []);;
But when I compile it, it returns me this error message:
Error: This expression has type 'a list
but an expression was expected of type unit
When I call the function, it works just fine, but it works just as expected, but what bothers me is the error message. Any idea why it appears?
PS: I use Emacs - Tuareg Mode as a text editor and compiler.