如何在OCaml中定义未初始化的数组?
我试着这样做:
let arr = Array.make_matrix 2 2
Error: The type of this expression, '_a -> '_a array array,
contains type variables that cannot be generalized
Run Code Online (Sandbox Code Playgroud)
当然我可以用0填充矩阵.但是后来我遇到了类型问题,因为我想在两个不同用户的数组输入和输出通道(ic和oc)中存储:
let fd, _ = conn in
let ic = Lwt_io.of_fd Lwt_io.Input fd in
let oc = Lwt_io.of_fd Lwt_io.Output fd in
Run Code Online (Sandbox Code Playgroud)
请告诉我,如何填写这样的阵列?
尝试使用答案.
let ic1 = ref None
...
ic1 := ic;
Error: This expression has type Lwt_io.input Lwt_io.channel
but an expression was expected of type 'a option
Run Code Online (Sandbox Code Playgroud)
let arr = Array.make_matrix 2 2 …Run Code Online (Sandbox Code Playgroud)