Created
November 9, 2011 22:47
-
-
Save JakubOboza/1353413 to your computer and use it in GitHub Desktop.
Syntax in Ocaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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:<" ;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);;