I'm going through the 99 problems on OCaml.org and I noticed that the solutions to the problems in many cases (e.g. problems 9, 10, 11, 12 to name some) follow the pattern:
let rev list =
let rec aux = function
| [] -> []
| h :: t -> h :: (aux t)
in
List.rev (aux list)
rather then simply gathering the elements with @
:
let rec rev = function
| [] -> []
| h :: t -> (rev t) @ [h]
(The above example is trivially simplified and stupid, used just for illustration.)
Is there any reason why using ::
and List.rev
is better, then using @
to append elements?