Effect of open List on printing of types

Consider the following:

$ ocaml
        OCaml version 4.13.1

# open List;;
# let rec split_toc_title a = function
  | '\\'::'n'::r -> rev a :: split_toc_title a r
  | x::xs -> split_toc_title (x::a) xs
  | [] -> [rev a];;

val split_toc_title : char List.t -> char List.t -> char list List.t = <fun>

The list type is printed both as list, and as the alias List.t, in particular in char list List.t it is surprising.

My intuition here is that List.t comes from the use of :: (due to the alias) and list from the use of rev (due to list.mli using list in the type of rev).

Is this expected, or should we expect OCaml to always use the same format when one type is an alias of another (i.e char List.t List.t or char list list)?

This is the expected resulted: without -short-paths when there are multiple aliases in scope for the same type, the specific alias used will depend on the inference path.


Thanks @octachron. I’ll do some reading up on -short-paths.

you can force it to use list by opening with a type rewrite, like this:

open (List : module type of List with type 'a t := 'a list)