简体   繁体   English

OCAML记录类型

[英]OCAML record type

I am creating an OCAML record type. 我正在创建OCAML记录类型。

type matrix =
{m_index:int;n_index:int;matrix:float array array}
;;

I have a function that takes two arguments and an array. 我有一个带有两个参数和一个数组的函数。

let create_matrix m n ={m_index=m;n_index=n;matrix=Array.make_matrix~dimx:m_index~dimy:n_index 0.};;

However, I get the following error, can anyone explain why? 但是,出现以下错误,有人可以解释原因吗?

Error: Unbound value m_index 错误:未绑定的值m_index

The problem is that you are using m_index as a right hand value to initialize a field of a record that you are creating. 问题是您使用m_index作为右手值来初始化正在创建的记录的字段。

While initializing a record that contains field m_index you can't use this field in an expression assigned to another field of the same object. 初始化包含字段m_index的记录时,不能在分配给同一对象的另一个字段的表达式中使用此字段。

Just use directly the m argument bound as the argument to create_matrix : 只需直接使用绑定的m参数作为create_matrix的参数即可:

let create_matrix m n = {
  m_index = m;
  n_index = n;
  matrix = Array.make_matrix m n 0.
};;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM