I am new to OCaml and have very little experience with functional programming. I have written the following function
let rec reverse l =
match l with
| [] -> []
| h::rest -> (reverse rest) @ h
which is supposed to reverse the elements in a list, transforming [1;2;3] into [3;2;1] for instance.
I don't know if the function will work but the issue is that OCaml infers that function to be of type 'a list list -> 'a list while I'd expect it to be an 'a list -> 'a list.
# reverse [1;2;3;4];;
Error: This expression has type int but an expression was expected of type 'a list