Pinch the Camel - OCaml

December 21st, 2007

OCaml is a strange beast of a language… at least to my imperative shaped brain. Some very very basic code:

(* define a function *)
# let sqr x = x * x;;
val sqr : int -> int = 

# sqr 5;;
- : int = 25

(* tuple,  *)
# (1, 2, 3);;
- : int * int * int = (1, 2, 3)

(* anonymous functions *)
# (fun x -> x * x) 2;;
val : int = 4

(* the “in” keyword was strange to me but now I an getting it *)
# let ipow3 x =
    let sqr x = x * x in
    x * sqr x;;
val ipow3 : int -> int = <fun>

Ocaml is an impure functional programming language. Impure because it also support imperative concepts, *O*Caml because it also supports object oriented programming. Now.. how do you make a shmup with that?

Leave a Reply