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

**URL:** <https://discuss.ocaml.org/t/help-t-t-some-problems-encountered-when-i-tried-to-implement-map-module/12797>\
**Category:** Learning\
**Created:** [August 11, 2023, 3:44am UTC](https://discuss.ocaml.org/t/help-t-t-some-problems-encountered-when-i-tried-to-implement-map-module/12797 "2023-08-11T03:44:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![featherwit001](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/featherwit001/32/4614_2.png) [@featherwit001](https://discuss.ocaml.org/u/featherwit001)\
**Post date:** [August 11, 2023, 3:44am UTC](https://discuss.ocaml.org/t/help-t-t-some-problems-encountered-when-i-tried-to-implement-map-module/12797/1 "2023-08-11T03:44:11Z")

</div>

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:

```OCaml
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?

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [August 11, 2023, 3:57am UTC](https://discuss.ocaml.org/t/help-t-t-some-problems-encountered-when-i-tried-to-implement-map-module/12797/2 "2023-08-11T03:57:35Z")

</div>

> [@featherwit001](#):
>
> May I ask how to operate to infer the type of key as int?

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![featherwit001](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/featherwit001/32/4614_2.png) [@featherwit001](https://discuss.ocaml.org/u/featherwit001)\
**Post date:** [August 11, 2023, 6:12am UTC](https://discuss.ocaml.org/t/help-t-t-some-problems-encountered-when-i-tried-to-implement-map-module/12797/3 "2023-08-11T06:12:03Z")

</div>

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