Archive for November 14th, 2007
module
Please ignore all the posts tagged with “ocaml”, I’m just posting them here for my reference.
renaming module: module Gr = Graphics;; (* all subsequent calls to Graphics will be Gr.xxx *)
named tuple: type tuple = {a : int; b : int}
string concatenation: ^
pattern guard: match x with SomePattern(a,b) [when a = b] -> …
assert: assert (x=5);;
print:
prerr_endline (“radius is ” ^ (string_of_int radius));
eprintf “radius is %d\n” radius;
compilation: (in cgywin with binutils and gcc installed)
ocamlopt -c amodule.ml
ocamlopt -c bmodule.ml
ocamlopt -o hello amodule.cmx bmodule.cmx
with interface (inerface must be compild first)
ocamlc -c amodule.mli
ocamlopt -c amodule.ml
module extension
module List =
struct
include List
let rec optmap f = function
[] -> []
| hd :: tl -> match f hd with
None -> optmap f tl
| Some x -> x :: optmap f tl
end
usage: open Extensions…
List.optmap …
Add comment 14 November 2007