我需要你的帮助,我的代码错误在哪里?
let create = Array.make_matrix 10 10;;
let assoc int = create int,create (char_of_int int);;
错误是
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
最佳答案
当你在 Ocaml 上隐式定义一个多态函数时,它有一个“弱类型”,这意味着在你调用它一次之后,类型肯定会被分配给该函数,所以因为你调用了 int 上的 create,所以现在它具有 int -> int 数组类型,并且不接受 char 作为参数。
关于ocaml - 我在使用 ocaml 多态函数时遇到了一些麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67040484/