|
@@ -0,0 +1,44 @@
|
|
|
|
+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» *)
|
|
|
|
+;;
|