I don't think it's possible. The reason is that OCaml throws away types at run time and therefore it is not possible to have a function which behave differently depending on a type at runtime. So you can't define such a polymorphic printing function. Note that #install_printer
is not part of the OCaml language but it a directive for the toplevel, which still knows about type. The only possible solution is to define a generic printing function which take the 'a
printing function as parameter. Something like
'a -> string -> 'a mylist -> unit
But I think you already know that, don't you ?