Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Time complexity of :: and @ (OCaml)

$
0
0

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} 

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>