Help. T^T Some Problems encountered when I tried to Implement Map Module

I tried to use AVL to write a map module myself, but an error was reported when using it.
The Make module written by myself has been introduced before,
and the example is as follows:

module Order_int_string: MyOrderType = struct
   type t = int
   let compare key1 key2 =
     key1 - key2
end

module MyMap = Make(Order_int_string)

let map_tree1 =
   let open MyMap in
   empty

let map_tree2 =
   let open MyMap in
   empty
   |> add 1 "1"

In add 1 β€œ1” on the last line,
The error is reported as:
int
This expression has type int but an expression was expected of type key ocamllsp.

Try to compile, the error is:
File β€œtest_tmp/bsts_test.ml”, line 156, characters 9-10:
156 | |> add 1 β€œ1”
^
Error: This expression has type int but an expression was expected of type key
I copied the map.ml in the standard library intact, and the above example still reported the same error.

questions

May I ask how to operate to infer the type of key as int?
Why is there no problem using the standard library directly?

Most likely by omitting the type annotation from the module definition:

module Order_int_string = struct
   type t = int
   let compare key1 key2 =
     key1 - key2
end

Why is there no problem using the standard library directly?

Most likely because the type annotation was omitted.

2 Likes

ohhhhhh!!!
it works!!!
Thank you very much

1 Like