Posts filed under 'ocaml'

basic Ocaml syntax

for variable = start [strong]to[/strong]/downto end do
    expression
done   List.iter f my_list (* f is a function that takes 1 argument *)

Add comment 23 December 2007

lablgtk compile

ocamlc -I +lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml

windows installation:

cygwin standard installation (select also binutils)

ocaml-mingw

gtk+-win32-devel : 2.10 :

lablgtk2, read the install file

Add comment 20 November 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


Calendar

November 2009
M T W T F S S
« Dec    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Posts by Month

Posts by Category