Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ocaml

Name: Anonymous 2008-12-16 11:06

Sup.

What does /prog/ think about ocaml?

Name: Anonymous 2008-12-18 2:12

recursively reversing a list

let rec reverselist l =
    match l with
    | [] -> []
    | car :: [] -> [car]
    | car :: cdr -> List.append (reverselist cdr) [car]


reversing a list with tail recursion

let rec tailrev l =
    let rec loop list acc =
        match list with
        | car :: cdr -> loop cdr (car :: acc)
        | _ -> acc
    loop l []

Name: Anonymous 2008-12-18 2:31

>>32
You don't need the rec in let rec tailrev l =

Name: Anonymous 2008-12-18 2:59

>>33
Ah, force of habit I guess. Good point.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List