41
What is ocaml? basic programming modules/signatures/functors object orientation tools things to read OCaml walkthrough Romain Slootmaekers June 24, 2011 Romain Slootmaekers OCaml walkthrough

OCaml Walkthrough

Embed Size (px)

DESCRIPTION

a quick overview of what ocaml has to offer

Citation preview

Page 1: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

OCaml walkthrough

Romain Slootmaekers

June 24, 2011

Romain Slootmaekers OCaml walkthrough

Page 2: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

Table of Contents I

1 What is ocaml?

2 basic programmingfunctionstypespolymorphismhigher order functionsimperative featureslabels/variants

3 modules/signatures/functorsmodules and signaturesfirst class modulesfunctors

4 object orientationRomain Slootmaekers OCaml walkthrough

Page 3: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

Table of Contents II

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

5 tools

6 things to read

Romain Slootmaekers OCaml walkthrough

Page 4: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is OCaml?

ML variantother ML variants:SML, F#, Moscow ML, Mythryl, . . .OCaml variants:MetaOCaml, JoCaml, OCamljs, . . .

compiled/interpretedbyte-code interpreter ←→ native code (speed ≈ * 7)

type inference

# l e t x = 5 ; ;v a l x : i n t = 5

strict typing

# [ 3 ; ”XX” ] ; ;E r r o r : Th i s e x p r e s s i o n has type s t r i n g butan e x p r e s s i o n was expec t ed o f type i n t

Gc,OO,simple FFI, . . .

Romain Slootmaekers OCaml walkthrough

Page 5: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

Trivial Examples(1)

l e t squa r e x = x ∗ x

l e t rec f a c n =i f n = 0then 1e l s e n ∗ f a c (n−1)

l e t rec f a c2 = f unct ion| 0 −> 1| n −> n ∗ f a c (n−1)

$ ocamlc -i trivial.ml

val square : int -> int

val fac : int -> int

val fac2 : int -> int

Romain Slootmaekers OCaml walkthrough

Page 6: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

Trivial Examples(2)

l e t avg x y = ( x+.y ) / . 2 .

l e t ( ∗∗∗ ) = avg

$ ocamlc -i trivial2.ml

val avg : float -> float -> float

val ( *** ) : float -> float -> float

Romain Slootmaekers OCaml walkthrough

Page 7: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

builtins

l e t l 0 = 1 : : 2 : : [ ] ; ;l e t l 1 = l 0 @ [ 3 ; 4 ] ; ;l e t l 2 = [ ( 1 , 1 ) ; ( 2 , 3 ) ] ; ;l e t s0 = "A string" ; ;s0 . [ 0 ] <− ’ a ’ ; ;l e t i = 4 2 ; ;l e t i 3 2 = 42 l ; ;l e t i 6 4 = 42L ; ;l e t a0 = [ | 1 . 1 ; 2 . 2 | ] ; ;a0 . ( 0 ) <− 0 . 0 ; ;s0 ; ;

$ ocamlc -i simple data.ml

val l0 : int list

val l1 : int list

val l2 : (int * int) list

val s0 : string

val i : int

val i32 : int32

val i64 : int64

val a0 : float array

Romain Slootmaekers OCaml walkthrough

Page 8: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

build your own

type f l i s t =| Empty| F l i s t of ( f l o a t ∗ f l i s t )

l e t ( ˆ . ) a b = F l i s t ( a , b )

l e t rec s i z e = f unct ion| Empty −> 0| F l i s t ( , s ) −> 1 + s i z e s

l e t ( ) =l e t f l = 3 .0 ˆ . 2 . 0 ˆ . 1 . 0 ˆ . Empty i nl e t s = s i z e f l i nP r i n t f . p r i n t f "the size is %i\n" s ; ;

Romain Slootmaekers OCaml walkthrough

Page 9: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

records

type s u i t = | Hear t s | Diamonds | Clubs | Spadestype rank = L of i n t | J | Q |K | Atype ca rd = { s u i t : s u i t ;

rank : rank }type hand = card a r r a y

l e t make card s r = { s u i t = s ; rank = r }

l e t my hand = [ | make card Hea r t s (L 2 ) ;make card Diamonds (L 3 ) ;make card Clubs (L 4 ) ;make card Spades (L 5 ) ;

| ]

Romain Slootmaekers OCaml walkthrough

Page 10: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

polymorphic functions

l e t rec s i z e = f unct ion| [ ] −> 0| : : r e s t −> 1 + s i z e r e s t

l e t ( ) =P r i n t f . p r i n t f "s1 = %i\n;s2 = %i\n"

( s i z e [ 1 ; 2 ; 3 ] )( s i z e [ ’ c ’ ; ’ h ’ ; ’ a ’ ; ’ r ’ ] ) ; ;

$ ocamlc -i pfunc.ml

val size : ’a list -> int = <fun>

Romain Slootmaekers OCaml walkthrough

Page 11: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

polymorphic functions(2)

l e t rec q s o r t = f unct ion| [ ] −> [ ]| p : : r e s t −>

l e t i s l e s s x = x < p i nl e t l , r = L i s t . p a r t i t i o n i s l e s s r e s t i nq s o r t l @ [ p ] @ q s o r t r

$ ocamlc -i pfunc2.ml

val qsort : ’a list -> ’a list = <fun>

Romain Slootmaekers OCaml walkthrough

Page 12: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

polymorphic types

type ’ a b t r e e = | Empty | Node of ’ a ∗ ’ a b t r e e ∗ ’ a b t r e e

l e t rec i n s e r t a = f unct ion| Empty −> Node ( a , Empty , Empty )| Node ( e , l , r ) as n when a = e −> n| Node ( e , l , r ) when a < e −> Node ( e , i n s e r t a l , r )| Node ( e , l , r ) −> Node ( e , l , i n s e r t a r )

l e t rec f r o m l i s t t r e e = f unct ion| [ ] −> t r e e| e : : e s −> f r o m l i s t ( i n s e r t e t r e e ) e s

l e t c t r e e = f r o m l i s t Empty [ ’ a ’ ; ’ l ’ ; ’ u ’ ; ’m’ ; ’ i ’ ; ’ n ’ ; ’ u ’ ; ’m ’ ] ; ;l e t i t r e e = f r o m l i s t Empty [ 3 ; 4 ; 5 ; 1 2 ; 5 ; 6 ; 1 ; 3 ] ; ;

Romain Slootmaekers OCaml walkthrough

Page 13: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

higher order functions

l e t rec f o l d l e f t f acc = f unct ion| [ ] −> acc| x : : x s −> f o l d l e f t f ( f acc x ) xs

l e t =P r i n t f . p r i n t f "sum=%i\n"

( f o l d l e f t (+) 0 [ 1 ; 2 ; 3 ; 4 ; 5 ] ) ; ;

$ ocamlc -i ho.ml

val fold_left : (’a -> ’b -> ’a)

-> ’a -> ’b list -> ’a = <fun>

Romain Slootmaekers OCaml walkthrough

Page 14: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

currying

open L i s t

l e t sum = f o l d l e f t (+) 0l e t prod = f o l d l e f t ( ∗ ) 1

l e t l e n xs = f o l d l e f t( fun a −> a+1) 0 xs

l e t oops = f o l d l e f t( fun a −> a+1) 0

$ ocamlc -i curry.ml

val sum : int list -> int

val prod : int list -> int

val len : ’a list -> int

val oops : ’_a list -> int

The type of this expression,

’_a list -> int,

contains type variables

that cannot be generalized

Romain Slootmaekers OCaml walkthrough

Page 15: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

for/while/references

l e t ( ) =f o r i = 0 to 5 do

P r i n t f . p r i n t f "i=%i " idone ;p r i n t n e w l i n e ( ) ;l e t j = r e f 0 i nwh i le ! j <= 5 do

P r i n t f . p r i n t f "j=%i " ! j ;i n c r j

done ;p r i n t n e w l i n e ( ) ; ;

$ ocaml for.ml

i=0 i=1 i=2 i=3 i=4 i=5

j=0 j=1 j=2 j=3 j=4 j=5

Romain Slootmaekers OCaml walkthrough

Page 16: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

labels

type po i n t = {x : f l o a t ; y : f l o a t ; z : f l o a t }l e t make po int ˜x ˜y ˜z = {x ; y ; z}l e t p2s p = P r i n t f . s p r i n t f

"{x=%.2f;y=%.2f;z=%.2f}"

p . x p . y p . z

l e t ( ) =l e t a , b , c = 1 . 0 , 2 . 0 , 3 . 0 i nl e t p0 = make po int

˜x : a ˜y : b ˜z : ci nl e t x , y , z = 4 . 0 , 5 . 0 , 6 . 0 i nl e t p1 = make po int

˜x ˜y ˜zi nP r i n t f . p r i n t f "p0=%s\np1=%s\n"

( p2s p0 ) ( p2s p1 ) ; ;

$ ocaml labels.ml

p0={x=1.00;y=2.00;z=3.00}

p1={x=4.00;y=5.00;z=6.00}

Romain Slootmaekers OCaml walkthrough

Page 17: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

functionstypespolymorphismhigher order functionsimperative featureslabels/variants

variants

l e t f = f unct ion| ‘On −> 1| ‘ Of f −> 0| ‘Number n −> n| −> −1;;

L i s t .map f [ ‘On ; ‘ Of f ; ‘ Whatever ] ; ;

$ ocamlc -i variants.ml

val f : [> ‘Number of int | ‘Off | ‘On ] -> int

Romain Slootmaekers OCaml walkthrough

Page 18: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

Example:lookup

l e t empty k = r a i s e Not foundl e t l ookup t k = t k

l e t i n s e r t t a b k =i f k = athen be l s e t k

$ ocamlc -i mod1.ml

val empty : ’a -> ’b

val lookup : (’a -> ’b) -> ’a -> ’b

val insert : (’a -> ’b) -> ’a -> ’b -> ’a -> ’b

Romain Slootmaekers OCaml walkthrough

Page 19: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

in a module

module Lookup = s t r u c tl e t empty k = r a i s e Not foundl e t l ookup t k = t k

l e t i n s e r t t a b k =i f k = athen be l s e t k

end

l e t t0 = Lookup . empty ; ;

open Lookupl e t t1 = i n s e r t t0 5 "five" ; ;l e t t2 = lookup t0 5 ; ;

$ ocamlc -i mod2.ml

module Lookup :

sig

val empty : ’a -> ’b

val lookup : (’a -> ’b) -> ’a

-> ’b

val insert : (’a -> ’b) -> ’a -> ’b -> ’a

-> ’b

end

val t0 : ’a -> ’b

val t1 : int -> string

val t2 : ’a

Romain Slootmaekers OCaml walkthrough

Page 20: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

with signature

module Lookup f : s i gtype ( ’ a , ’ b ) t = ’ a −> ’ bv a l empty : ( ’ a , ’ b ) tv a l l ookup : ( ’ a , ’ b ) t −> ’ a −> ’ bv a l i n s e r t : ( ’ a , ’ b ) t −> ’ a −> ’ b −> ( ’ a , ’ b ) t

end = s t r u c ttype ( ’ a , ’ b ) t = ’ a −> ’ bl e t empty k = r a i s e Not foundl e t l ookup t k = t kl e t i n s e r t t a b k =

i f k = athen be l s e t k

endl e t t0 = Lookup f . empty ; ;l e t t1 = Lookup f . i n s e r t t0 5 "five" ; ;l e t t2 = Lookup f . l ookup t0 5 ; ;

Romain Slootmaekers OCaml walkthrough

Page 21: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

multiple implementations

module type L = s i gtype tv a l empty : u n i t −> tv a l l ookup :

t −> i n t −> s t r i n gv a l i n s e r t :

t −> i n t −> s t r i n g −> tend

open Lookup

module F = ( s t r u c ttype t = i n t −> s t r i n gl e t empty k = r a i s e Not foundl e t l ookup t k = t kl e t i n s e r t t a b k =

i f k = athen be l s e t k

end : L )

Romain Slootmaekers OCaml walkthrough

Page 22: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

multiple implementations(2)

module A = ( s t r u c ttype t = ( i n t ∗ s t r i n g ) l i s tl e t empty ( ) = [ ]l e t rec l ookup t k = match t with| [ ] −> r a i s e Not found| ( a , b ) : : r e s t −>

i f k = athen be l s e l ookup r e s t k

l e t i n s e r t t a b = (a , b ) : : tend : Lookup . L )

Romain Slootmaekers OCaml walkthrough

Page 23: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

multiple implementations(3)

module H = ( s t r u c ttype t = ( i n t , s t r i n g ) Hashtb l . tl e t empty ( ) = Hashtb l . c r e a t e 17l e t l ookup t k = Hashtb l . f i n d t kl e t i n s e r t t a b = Hashtb l . add t a b ; tl e t nobody w i l l know ( ) = ( )

end : Lookup . L )

Romain Slootmaekers OCaml walkthrough

Page 24: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

example usage

open Lookup fopen Lookup hopen Lookup a

l e t f 0 = F . empty ( ) ; ;l e t f 1 = F . i n s e r t f 0 5 "five" ; ;l e t f v = F . lookup f0 5 ; ;

l e t l 0 = A. empty ( ) ; ;l e t l 1 = A. i n s e r t l 0 5 "five" ; ;l e t l v = A. lookup l 1 5 ; ;

l e t h0 = H. empty ( ) ; ;l e t h1 = H. i n s e r t h0 5 "five" ; ;l e t hv = H. lookup h1 5 ; ;

Romain Slootmaekers OCaml walkthrough

Page 25: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

watch out

open Lookup hopen Lookup a

l e t no way= H. empty ( ) ; ;l e t oops = A. i n s e r t no way 5 ” f i v e ” ; ;

$ ocamlbuild liskov.byte

File "liskov.ml", line 5, characters 20-26:

Error: This expression has type Lookup_h.H.t

but an expression was expected of type

Lookup_a.A.t

Romain Slootmaekers OCaml walkthrough

Page 26: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

example

module type DEVICE = s i g v a l i n i t : u n i t −> un i t endmodule PDF = s t r u c t l e t i n i t ( ) = ( ) endmodule SVG = s t r u c t l e t i n i t ( ) = ( ) end

l e t d e v i c e s = Hashtb l . c r e a t e 17l e t ( ) =Hashtb l . add d e v i c e s "PDF" (module PDF: DEVICE)l e t ( ) =Hashtb l . add d e v i c e s "SVG" (module SVG : DEVICE)

module Dev ice =( v a l (

t r y Hashtb l . f i n d d e v i c e s Sys . a rgv . ( 1 )with Not found −> p r e r r e n d l i n e "Unknown device" ; e x i t 2)

: DEVICE)

l e t ( ) = Dev ice . i n i t ( ) ; ;

Romain Slootmaekers OCaml walkthrough

Page 27: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

Map example

module Str ingMap = Map .Make( S t r i n g )

open Str ingMap

l e t ( ) =l e t s0 = add "5" "five" empty i nl e t v = f i n d "5" s0 i nP r i n t f . p r i n t f "v=%s\n" v ; ;

Romain Slootmaekers OCaml walkthrough

Page 28: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

modules and signaturesfirst class modulesfunctors

ROY

module type E = s i gtype tv a l compare : t −> t −> i n t

end

module Set = f u n c t o r ( E l t : E) −>s t r u c t

type e l ement = E l t . ttype t r e e =| Empty| Node of ( e l ement ∗

t r e e ∗ t r e e )

l e t empty = Empty

l e t rec add x s=f a i l w i t h "todo"

l e t rec mem x = f unct ion| Empty −> r a i s e Not found| Node ( e , , ) when e = x −> t r u e| Node ( e , l , r ) −>

i f E l t . compare e x < 0then mem x le l s e mem x r

end

module S t r i n g S e t = Set ( S t r i n g )

Romain Slootmaekers OCaml walkthrough

Page 29: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

objects

classes

interfaces

initializers

(multiple) inheritance

public/private

parametrization

open types

Romain Slootmaekers OCaml walkthrough

Page 30: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

immediate objects

l e t p =ob j e c tv a l mutable x = 0method g e t x = xmethod move d = x <− x + d

end

$ ocamlc -i ad hoc.ml

val p : < get_x : int; move : int -> unit >

Romain Slootmaekers OCaml walkthrough

Page 31: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

simple class with immutable objects

c l a s s p o i n t x y z =l e t l = s q r t ( x ∗ . x +. y ∗ . y +. z ∗ . z ) i n

o b j e c t ( s e l f )method l e n g t h = lmethod t o s t r i n g =

P r i n t f . s p r i n t f"{%.2f;%.2f;%.2f}"

x y zend

l e t ( ) =l e t p = new po i n t 1 . 2 . 3 .i nP r i n t f . p r i n t f

"p=%s;||p|| = %2.f\n"

( p # t o s t r i n g )( p # l e ng t h ) ; ;

$ ocamlc -i point class.ml

class point :

float ->

float ->

float -> object

method length : float

method to_string : string

end

Romain Slootmaekers OCaml walkthrough

Page 32: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

class types

c l a s s type p r i n t a b l e = ob j e c tmethod t o s : u n i t −> s t r i n g

endc l a s s p o i n t x y =ob j e c t ( s e l f : #p r i n t a b l e )

method t o s ( ) =P r i n t f . s p r i n t f "{%.2f;%.2f}"

x yendc l a s s c i r c l e p r =ob j e c t ( s e l f : #p r i n t a b l e )

method t o s ( ) =P r i n t f . s p r i n t f "C(%s,%2.f)"

( p # t o s ( ) ) rend

l e t p0 = new po i n t 0 . 0 .l e t c0 = new c i r c l e p0 1 .0l e t o b j e c t s = [ p0 ; c0 ]l e t ( ) =

L i s t . i t e r( fun o −>

l e t os = o # t o s ( ) i nP r i n t f . p r i n t f "%s\n" os )

o b j e c t s ; ;

Romain Slootmaekers OCaml walkthrough

Page 33: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

gotchas

calls on self during construction?

downcasts?

polymorphic methods?

polymorphic exceptions?

Romain Slootmaekers OCaml walkthrough

Page 34: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

parametrization

c l a s s [ ’ a ] l i n k e d l i s t ( a : ’ a ) = ob j e c tv a l mutable next = Nonemethod s e t n e x t ( t a i l : ’ a l i n k e d l i s t ) =

next <− Some t a i lend

l e t ( ) =l e t l 0 = new l i n k e d l i s t "a" i nl e t l 1 = new l i n k e d l i s t "b" i nl 0 # s e t n e x t l 1 ; ;

Romain Slootmaekers OCaml walkthrough

Page 35: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

What is there?ad hoc objectsbasic OOparametrizationad hoc interfaces

example

l e t l o g o o x =l e t k s = l e t os = o # t o s t r i n g ( ) i n

Lwt log . debug ( os ˆ": " ˆ s )i nP r i n t f . k s p r i n t f k x

$ ocamlfind ocamlc -i -package lwt.unix log o.ml

val log_o :

< to_string : unit -> string; .. > ->

(’a, unit, string, unit Lwt.t) format4 -> ’a

Romain Slootmaekers OCaml walkthrough

Page 36: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

ocamlc, ocamlopt, ocamlc.opt, ocamlopt.opt

ocamlfind

ocamlbuild

emacs, eclipse, omlet, camelia, . . .

others

Romain Slootmaekers OCaml walkthrough

Page 37: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

ocamlfind

knows which packages you have

fills in details for the compilers

Example

$ ocamlopt EchoServer.ml

File "EchoServer.ml", line 1, characters 0-1:

Error: No implementations provided for

the following modules:

Unix referenced from EchoServer.cmx

$ ocamlopt.opt /.../lib/ocaml/unix.cmxa EchoServer.ml

$ ocamlfind

ocamlopt -package unix -linkpkg EchoServer.ml

Romain Slootmaekers OCaml walkthrough

Page 38: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

ocamlbuild

builds things

declarative

target extension

plugins for (c)libraries, documentation, profiler,...

tags

myocamlbuild.ml

Romain Slootmaekers OCaml walkthrough

Page 39: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

IDEs

emacs: tuareg

eclipse: ocaide http://www.algo-prog.info/ocaide/

camelia http://camelia.sourceforge.net/

vim: omlet

. . . lots of dead projects

Romain Slootmaekers OCaml walkthrough

Page 40: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

developing applications with OCamlhttp://caml.inria.fr/pub/docs/oreilly-book/

The Objective Caml system http:

//caml.inria.fr/pub/docs/manual-ocaml/index.html

Jane street bloghttp://ocaml.janestreet.com/?q=node/89

Lambda The Ultimate http://lambda-the-ultimate.org/

Romain Slootmaekers OCaml walkthrough

Page 41: OCaml Walkthrough

What is ocaml?basic programming

modules/signatures/functorsobject orientation

toolsthings to read

advanced stuff

. . . Next time

Romain Slootmaekers OCaml walkthrough