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 =
match something with
Record r -> r.foo ()
| Object o -> o#foo ();;
do_foo (Record foo_rec);;
do_foo (Object foo_obj);;
dHlwZSByZWNvcmRfdHlwZSA9IHtmb28gOiB1bml0IC0+IHVuaXR9OzsKdHlwZSBvYmplY3RfdHlwZSA9IDxmb28gOiB1bml0IC0+IHVuaXQ+OzsKdHlwZSBlaXRoZXIgPSBSZWNvcmQgb2YgcmVjb3JkX3R5cGUgfCBPYmplY3Qgb2Ygb2JqZWN0X3R5cGU7OwoKbGV0IGRvX2ZvbyBzb21ldGhpbmcgPQogICAgbWF0Y2ggc29tZXRoaW5nIHdpdGgKICAgICAgICBSZWNvcmQgciAtPiByLmZvbyAoKQogICAgICB8IE9iamVjdCBvIC0+IG8jZm9vICgpOzsKICAgICAgICAKICAgICAgICAKbGV0IGZvb19yZWMgPSB7Zm9vID0gKGZ1biAoKSAtPiBwcmludF9lbmRsaW5lICJmb28iKX07OwpsZXQgZm9vX29iaiA9IG9iamVjdCBtZXRob2QgZm9vICgpID0gcHJpbnRfZW5kbGluZSAiZm9vIiBlbmQ7OwoKZG9fZm9vIChSZWNvcmQgZm9vX3JlYyk7Owpkb19mb28gKE9iamVjdCBmb29fb2JqKTs7