我不知道为什么ReasonML会引发此错误

我正在尝试在ReasonmL中创建一个程序来执行以下操作:

scanRight(add,[1,1,2,3,5],0);

/* Intermediate Steps
[(add 1 (add 1 (add 2 (add 3 (add 5 0))))),(add 1 (add 2 (add 3 (add 5 0)))),(add 2 (add 3 (add 5 0))),(add 3 (add 5 0)),(add 5 0),0] */

/* Final Output */
[12,11,10,8,5,0]

这是我编写的过程:

let rec scanRight: (('a,'b) => 'b,list('a),'b) => list('b) = (proc,lst,base) =>
switch(lst){
    |[] => [base]
    |[hd,... tl] => List.flatten([proc(hd,scanRight(proc,tl,base)),base)])
};

但是,它一直给我这个错误:

  2 │ switch(lst){
  3 │     |[] => [base]
  4 │     |[hd,... tl] => **List.flatten([proc(hd,base)])**
  5 │ };
  6 │

  This has type:
    list('a)
  But somewhere wanted:
    list(list('a))
  The type variable 'a occurs inside list('a)

我不确定在list(list('a))的确切位置,因为我的类型签名指示输出应为list('a)类型。

编辑:当我取出List.flatten()时会引发此错误:

  1 │ let rec scanRight: (('a,'b) => list('b) = **(proc,base) =>
  2 │ switch(lst){
  3 │     |[] => [base]
  4 │     |[hd,... tl] => [proc(hd,scanRight(pr
      oc,base)]
  5 │ };**

  This has type:
    (('a,list('b)) => list('b),list('b)) => list(list('b))
  But somewhere wanted:
    (('a,list('b)) => list('b)
  The type variable 'b occurs inside list('b)
dahuaabcd123 回答:我不知道为什么ReasonML会引发此错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3044158.html

大家都在问