this week: programming-in-the-large using the module system of OCaml.
in large project: mangage high number of definitions → abstractions built on top of other abstractions.
dot-notation: access module …
functional language:
but imperative features are useful:
syntax for functional expr: function some_identifier -> some_expr
the type of the functional expr is t1 -> t2 where t1 is the type of some_identifier, t2 is type of some_expr
ex.
function x -> x + 1;;
(function x -> 2*x) 5;; (*annonymous function*)
the previous way of defining function:
let …
Last week, we only defined flat data structures which are nice to aggregate values but quite limited when you try to structure values.
This week: algebraic datatypes.
⇒ change the return type to a type query_result, which can be either of these:
this week: structure code with types: tuples, records, arrays.
type type_identifier = some_type to define a new type (type_identifier is synonym/abbrevation of some_type) type_identifier must start with lowercase letter int, bool, string, char ... : to add …Rich type system and polymorphism in ocaml. Types are infered not declared.
Basic types: int, bool, float, string, char, ...
value: $-2^{62}$ ~ $2^{62}-1$ on 64-bit machines.
ops: +, -, *, /, mod (reminder: / is integer division)
# 3+2*4-1;;
- : int = 10
# 5/2;;
- : int …statically strongly typed languages
expressiveness: functional+type inference+polymorphism
package manager: opam
programming environment fully online: https://try.ocamlpro …