Functional core of Objective CAML:
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora015.htmlVariables are variable:
# letp
=
1
0
;;
val p : int = 10
# letk
x
=
(x
,
p
,
x
+
p);;
val k : int -> int * int * int =
# kp
;;
- : int * int * int = 10, 10, 20
# letp
=
1
0
0
0
;;
val p : int = 1000
# kp
;;
- : int * int * int = 1000, 10, 1010
http://caml.inria.fr/pub/docs/manual-ocaml/expr.html
Looping:
while expr1 do expr2 done
for name = expr1 to expr2 do expr3 done
for name = expr1 downto expr2 do expr3 done
Exceptions: try ... with ... -> ...
Objects
Coercion (casting to superclass): subobject :> superclass
Message sending (calling method on object): object # method
Object duplication: Oo.copy
Recursive functions: rec
String concatenation: ^
Characters delimited by ` not ': `a`
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016.html#toc21
Tuples
Records
Sum Types
Constant Constructor: typesuit
=
Spades
|
Hearts
|
Diamonds
|
Clubs
;;
Constructor with Args: typecard
=
King
of
suit
|
Queen
of
suit
|
Knight
of
suit
|
Knave
of
suit
|
Minor_card
of
suit
*
int
|
Trump
of
int
|
Joker
;;
Recursive Types
Parameterised Types: type('a
,
'b)
list2
=