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

O'Caml

Name: Anonymous 2011-07-31 14:16

Good day, fellow /prog/raiders.
I am currently learning O'Caml, what should I pay attention? What is Bad and what is Good on this language?

Name: Anonymous 2011-08-03 8:38

>>38,39
It's always let x = 3 in. Not let x = 3;


let divide x y = x / y, x mod y ;;

let rec extended_gcd a b =
    if a > b then extended_gcd b a
    else
        if b = 0 then (1, 0)
        else
            let qr = divide a b in
            let st = extended_gcd b (snd qr) in
            (snd st, (fun s q t -> s - q * t) (fst st) (fst qr) (snd st))
;;



Also, this took me a while to figure out: If you are going to put multiple statements in an if block then you have to start with begin ... end. Ex:

let rec extended_gcd a b =
    if a > b then extended_gcd b a
    else
        if b = 0 then (1, 0)
        else begin
            Printf.printf "a: %d b: %d" a b ;
            let qr = divide a b in
            let st = extended_gcd b (snd qr) in
            (snd st, (fun s q t -> s - q * t) (fst st) (fst qr) (snd st))
        end
;;

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