I was reading this and was wondering if ::
is always more efficient than @ or if only in that particular implementation of rev
let rec rev = function | [] -> [] | h::t -> rev t @ [h]let rev l = let aux accu = function | [] -> accu | h::t -> aux (h :: accu) t
For example, if I wanted to append an element on a queue, would there be a difference in these two methods:
let append x q = q @ [x]
and
type 'a queue = {front:'a list; back:'a list} let norm = function | {front=[]; back} -> {front=List.rev back; back=[]} | q -> q let append x q = norm {q with back=x::q.back}