Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created November 9, 2011 22:47
Show Gist options
  • Save JakubOboza/1353413 to your computer and use it in GitHub Desktop.
Save JakubOboza/1353413 to your computer and use it in GitHub Desktop.
Syntax in Ocaml
Printf.printf "Hello out there\n%!";;
let rec fibonacci n = if n < 3 then 1 else fibonacci (n-1) + fibonacci (n-2);;
Printf.printf "Please enter an integer number: %!";;
let n = read_int ()
in Printf.printf "The %d'th Fibonacci number is %d\n%!" n (fibonacci n);;
(* run it by "ocaml fib.ml" or compile "ocamlopt -o fib fib.ml"*)
(* this is a comment, yes it is sick to put comments like this *)
let hypo (a, b) =
let sq x = x *. x in
sqrt( sq a +. sq b ) ;;
(* this let expr in syntax roxx hard *)
hypo (5.2, 6.1) ;;
- : float = 8.0156097709407
Printf.sprintf "Hi guys my name is %s\n", "sprintf fun:<" ;;
@JakubOboza
Copy link
Author

let fib k =
let rec fib3 (n, a, p, pp) = if n == a then pp else fib3(n, a + 1, p + pp, p )
in fib3(k, 1, 1, 1);;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment