ocaml-community / utop

Universal toplevel for OCaml
Other
833 stars 110 forks source link

type aliases weird behavior #476

Closed puitgfr closed 5 months ago

puitgfr commented 5 months ago

Type aliases seem to be incorrectly managed.

§ utop
Welcome to utop version 2.13.1 (using OCaml version 4.14.1)!
Type #utop_help for help about using utop.

utop [0]:  type nat = int  (* ≥ 0 *) ;;
type nat = int
utop [1]:  let rec fact (n:nat) : nat =
             if n <= 1 then 1 else n * fact (n-1) ;;
utop [2]:  fact 5 ;;
- : nat = 120

So far, so good. But :

utop [3]: (+) ;;
- : nat -> nat -> nat = <fun>

Maybe I'm missing something about type aliases, but I 'd like the type of (+) to remain int -> int -> int, as it is the case in standard toplevel ocaml.

emillon commented 5 months ago

That's because utop uses -short-paths by default. You will get the same behavior in a ocaml toplevel if you pass -short-paths. You can disable this behavior in utop by passing -no-short-paths. Thanks

puitgfr commented 5 months ago

Thanks for your quick reply. Indeed, it works with -no-short-paths. I wasn't aware of this option :+1: