type record_type
= {foo
: unit -> unit};; type object_type
= <foo
: unit -> unit
>;; type either = Record of record_type | Object of object_type;;
let do_foo (something : either) =
match something with
Record r -> r.foo ()
| Object o -> o#foo ();;
do_foo (Record foo_rec);;
do_foo (Object foo_obj);;
dHlwZSByZWNvcmRfdHlwZSA9IHtmb28gOiB1bml0IC0+IHVuaXR9OzsKdHlwZSBvYmplY3RfdHlwZSA9IDxmb28gOiB1bml0IC0+IHVuaXQ+OzsKdHlwZSBlaXRoZXIgPSBSZWNvcmQgb2YgcmVjb3JkX3R5cGUgfCBPYmplY3Qgb2Ygb2JqZWN0X3R5cGU7OwoKbGV0IGRvX2ZvbyAoc29tZXRoaW5nIDogZWl0aGVyKSA9CiAgICBtYXRjaCBzb21ldGhpbmcgd2l0aAogICAgICAgIFJlY29yZCByIC0+IHIuZm9vICgpCiAgICAgIHwgT2JqZWN0IG8gLT4gbyNmb28gKCk7OwogICAgICAgIAogICAgICAgIApsZXQgZm9vX3JlYyA9IHtmb28gPSAoZnVuICgpIC0+IHByaW50X2VuZGxpbmUgImZvbyIpfTs7CmxldCBmb29fb2JqID0gb2JqZWN0IG1ldGhvZCBmb28gKCkgPSBwcmludF9lbmRsaW5lICJmb28iIGVuZDs7Cgpkb19mb28gKFJlY29yZCBmb29fcmVjKTs7CmRvX2ZvbyAoT2JqZWN0IGZvb19vYmopOzs=