Tag Archives: tail recursion

F# Flatten argv Into A Flat String Using Tail Recursion

let squashStrArray (str_arg : string[]) =
    let array_len = str_arg.Length
    let rec inner_squash (inner_str_arg : string []) (build_up_list : string) idx =
    if idx = array_len then
       build_up_list
    else
       let build_up_list = inner_str_arg.[idx] + " " + build_up_list
       inner_squash inner_str_arg build_up_list (idx + 1)

    inner_squash str_arg "" 0

Advertisements

Leave a comment

Filed under F#, Programming