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:
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.
May I ask how to operate to infer the type of key as int?
Why is there no problem using the standard library directly?