fork download
  1. type record_type = {foo : unit -> unit};;
  2. type object_type = <foo : unit -> unit>;;
  3. type either = Record of record_type | Object of object_type;;
  4.  
  5. let do_foo something =
  6. match something with
  7. Record r -> r.foo ()
  8. | Object o -> o#foo ();;
  9.  
  10.  
  11. let foo_rec = {foo = (fun () -> print_endline "foo")};;
  12. let foo_obj = object method foo () = print_endline "foo" end;;
  13.  
  14. do_foo (Record foo_rec);;
  15. do_foo (Object foo_obj);;
Success #stdin #stdout 0.01s 2780KB
stdin
Standard input is empty
stdout
foo
foo