(* this is a comment *) (* this is a (* nested *) comment *) (* Copy & paste lines from this file to the interactive Ocaml environment * to see the output. * Or type * #use "01-Intro.ml";; * to load this file *) (* Defining variables and functions with "let" *) let x = 3;; let sum x y = x + y;; sum x 6;; (* Printing *) print_int 13;; print_string "hello";; (* Arithmetic and boolean operations *) (* Use + - * / for integers and +. -. *. /. for floats *) let d = 3.4 +. 6.7;; 3 > 4 || true;; if x > 10 then print_string "greater" else print_string "smaller";; (* Use parentheses generously *) if x < 10 then 10 else 20 + 5;; (* gives 10 *) (if x < 10 then 10 else 20) + 5;; (* gives 15 *) (* Sequencing is done with ; *) print_int 42; print_string "\n";; (* Characters are defined with single quotes *) let c = 'a';; int_of_char c;; char_of_int 97;; (* Use double quotes for strings, ^ for concatenation. * The String module contains useful functions *) let cons s = "hello "^s^"\n";; print_string (cons "world");; String.length "abcd";; let j = int_of_string "123" + 7;; (* j = 130 *)