module

14 November 2007

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 …

Entry Filed under: ocaml, programming. .

Leave a Comment

hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

November 2007
M T W T F S S
« Oct   Dec »
 1234
567891011
12131415161718
19202122232425
2627282930  

Most Recent Posts