gdritter repos bricoleur / master examples / structural-types / ocaml-source / main.ml
master

Tree @master (Download .tar.gz)

main.ml @masterraw · history · blame

let () = print_endline "Hello!";;

(* «classes» *)
class cat = object
  method speak = print_endline "meow"
end
class dog = object
  method speak = print_endline "woof"
end
(* «end» *)

(* «uses» *)
let hear_what_it_has_to_say obj =
  let () = obj#speak in ()
(* «end» *)
;;

(* «calling» *)
let () = hear_what_it_has_to_say (new cat)
(* prints "meow" *)
let () = hear_what_it_has_to_say (new dog)
(* prints "woof" *)
(* «end» *)
;;

(* «bigger-object» *)
class cow = object
  method speak = print_endline "moo"
  method num_stomachs = 4
end
(* «end» *)
;;

(* «call-cow» *)
let () = hear_what_it_has_to_say (new cow)
(* prints "moo" *)
(* «end» *)
;;

(* «speaker» *)
let ecce_orator obj =
  let () = obj#speak in obj
(* «end» *)
;;