如何在OCaml / ReasonML中声明功能参数?

有两个功能; funA funB a.i,a.o,ah,w,c是函数 funA 中的数组。函数 funA 应该作为功能参数传递给函数 funB ,并且数组应该可以由函数 funB 访问。不幸的是,语法检查器遇到错误“错误:未绑定记录字段a”。请发表评论,如何在OCaml / ReasonmL中声明功能参数?

完整列表

module Test = {
    let vector = Array.init;
    let matrix = (m,n,f) => vector(m,i => vector(n,f(i)));
    let length = Array.length;
    let rand = (x0,x1) => x0 +. Random.float(x1 -. x0);
    let funA = (ni,nh,no) => {
      let init = (fi,fo) => {
        let i = matrix(ni + 1,fi);
        let o = matrix(nh,no,fo);
        ();
      };

      let a = {
        let i = vector(ni + 1,_ => 1.0);
        let o = vector(no,_ => 1.0);
        ();
      };

      let ah = vector(nh,_ => 1.0);
      let w = init((_,_) => rand(-0.2,0.4),(_,_) => rand(-2.0,4.0));
      let c = init((_,_) => 0.0,_) => 0.0);
      ();
    };

    let funB = (net,inputs) => {
      let (ni,no) = (
        length(net.a.i),length(net.ah),length(net.a.o),);
      ();
    };
  };
csz802864 回答:如何在OCaml / ReasonML中声明功能参数?

要解析功能 funB 中无法访问的功能参数 funA ,请在模块开头应用以下类型。

module Test = {

    type io('a) = {
      i: 'a,o: 'a,};

    type vec = array(float);

    type mat = array(vec);

    type funA = {
      a: io(vec),ah: vec,w: io(mat),c: io(mat),};

.......
本文链接:https://www.f2er.com/2592865.html

大家都在问