« Return to Thread: tail recursion

Re: "ocaml_beginners"::[] tail recursion

by Karl Zilles :: Rate this Message:

Reply to Author | View in Thread

Jon Harrop wrote:
> let rec rev_append l1 l2 =
> match l1, l2 with
> | [], l2 -> l2
> | hd::tl, l2 -> rev_append tl (hd::l2);;

Or, less verbosely...

let rec rev_append l1 l2 =

   match l1 with

   | [] -> l2
   | hd::tl -> rev_append tl (hd::l2);;

 « Return to Thread: tail recursion