Can one make type coercion work without using mli files?

I very rarely use mli files in my OCaml programming. IMHO Ocaml would be better
if it allowed for specifying some basic interface information in the ml file directly,
such as whether a value or type is hidden in the interface
(this is what the private keyword does in OO languages) and constraining the type of
some values. Why achieve with one more long file what you can (or should be able to) achieve with a few more words in the original file ?

In that regard, I find that the type coercion operations (:) and (:>) in OCaml do not
do what they would be expected to do, except 1) for object types and 2) as mere type-checking devices, i.e. if (:) or (:>) are used with incompatible types, then the compiler will complain.

Consider the following example in the toplevel :

Here, the toplevel ignores my request that the values returned by g be displayed
as a ints, and displays y1 as a int_carbon_copy.
Is there a way to get around this without using mli files ?

I guess utop is using -short-paths for some reason.

1 Like

See OCaml interface files–hero or menace? - DEV Community

1 Like