我在 OCaml 中创建了一个可变数据结构,但是当我访问它时,它给出了一个奇怪的错误,
这是我的代码
type vector = {a:float;b:float};;
type vec_store = {mutable seq:vector array;mutable size:int};;
let max_seq_length = ref 200;;
exception Out_of_bounds;;
exception Vec_store_full;;
let vec_mag {a=c;b=d} = sqrt( c**2.0 +. d**2.0);;
let make_vec_store() =
let vecarr = ref ((Array.create (!max_seq_length)) {a=0.0;b=0.0}) in
{seq= !vecarr;size=0};;
当我在 ocaml 顶层执行此操作时
let x = make _ vec _store;;
然后尝试做x.size
我得到这个错误
Error: This expression has type unit -> vec_store
but an expression was expected of type vec_store
什么似乎是问题?我不明白为什么这不起作用。
谢谢,费萨尔