




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















( A small OCaml program ) let x = 37;; let y = x + 5;; print_int y;; print_string "\n";;
% ocamlc ocaml1.ml % ./a.out 42 %
( A small OCaml program ) let x = 37;; let y = x + 5;; print_int y;; print_string "\n";;
# 3 + 4;;
- : int = 7
# let x = 37;; val x : int = 37
# x;;
- : int = 37
# let y = 5;; val y : int = 5
# let z = 5 + x;; val z : int = 42
# print_int z;; 42- : unit = ()
# print_string "Colorless green ideas sleep furiously";; Colorless green ideas sleep furiously- : unit = ()
# print_int "Colorless green ideas sleep furiously";; This expression has type string but is here used with type int
# 1 + true;; This expression has type bool but is here used with type int
**let pi = 3.14 in pi . 3.0 . 3.0;; pi;;
**let pi = 3.14 in let r = 3.0 in pi . r . r;; ( pi, r no longer in scope )
float pi = 3.14; float r = 3.0;
pi * r * r; } / pi, r not in scope /
let next x = x + 1;; next 3;; let plus (x, y) = x + y;; plus (3, 4);;