ocamlmlcamltoplevel

I got some trouble with ocaml polymorphic function


i need your help please, where is the error in my code ?

let create = Array.make_matrix 10 10;;

let assoc int = create int,create (char_of_int int);;

the error is

3 | let assoc int = create int,create (char_of_int int);;
                                      ^^^^^^^^^^^^^^^^^
Error: This expression has type char but an expression was expected of type
         int

Solution

  • when you define a polymorphic function implicitly on Ocaml, it has a `weak type meaning that a type will be definitely assigned to the function after you've called it once, so because you called to create on an int, it now has a type int -> int array and won't accept a char as an argument.