




























































































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!





























































































AT&T Research, Univ. of Chicago (among others)
for Research in Computer Science)
Applications with
Objective Caml
Objective Caml
Programming
Language
in C++)
( This is an OCaml program )
let x = 37;;
let y = x + 5;;
print_int y;;
print_string
"\n";;
Use (* *) for comments (may nest)
;; ends a top-level expression
Use let to bind variables
No type declarations
Need to use correct print function
(OCaml also has printf)
(“compiled interface”) files
42 : int true : bool
"hello" : string 'c' : char
3.14 : float () : unit (* don’t care value *)
# 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;;
Bind pi in body of let
mult. on floating point
Error
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);;
Use let to define functions
List arguments after fn name
No return statement No parens on fun calls
domain type t1 and return or range type t
( type int -> float )
let (x : int) = 3
let z = (x : int) + 5
let foo (x:int):float =
*(float_of_int x) . 3.