« Return to Thread: tail recursion

tail recursion

by stevewirts :: Rate this Message:

Reply to Author | View in Thread

could anyone tell me if this is tail recursive?

let append l1 l2 =
        let rl1 = List.rev l1 in
          let rec rappend l1 l2 =
      if l1 = [] then l2
      else
      let hd = List.hd l1 in
      let tl = List.tl l1 in
      let larger = hd :: l2 in
      rappend tl larger
           in rappend rl1 l2;;
         
# append [1;2;3] [4;5;6];;
- : int list = [1; 2; 3; 4; 5; 6]

 « Return to Thread: tail recursion