Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更正此haskell对数函数? natlog x=直到条件计数(1,1,0) 哪里 cond(u,val,u)=val_Haskell_Functional Programming - Fatal编程技术网

如何更正此haskell对数函数? natlog x=直到条件计数(1,1,0) 哪里 cond(u,val,u)=val

如何更正此haskell对数函数? natlog x=直到条件计数(1,1,0) 哪里 cond(u,val,u)=val,haskell,functional-programming,Haskell,Functional Programming,此函数用于尝试计数日志1+x 问题类似于 错误代码: natlog x = until cond count (1,1,0) where cond (_,val,_) = val < 0.001 count (i,val,sum) = (i+1,(-x)^i/i,sum+val) :1:8: 约束中不明确的类型变量“t0”: (Num t0)源于1:8处的文字“1” (积分t0)因在1:1-6使用“natlog”而产生 (分数t0)由于使用“na

此函数用于尝试计数日志1+x

问题类似于

错误代码:

natlog x = until cond count (1,1,0)
    where 
        cond (_,val,_) = val < 0.001
        count (i,val,sum) = (i+1,(-x)^i/i,sum+val)
:1:8:
约束中不明确的类型变量“t0”:
(Num t0)源于1:8处的文字“1”
(积分t0)因在1:1-6使用“natlog”而产生
(分数t0)由于使用“natlog”而产生
时间:1:1-6
可能修复:添加修复这些类型变量的类型签名
在'natlog'的第一个参数中,即'1'
在表达式中:natlog 1
在“it”的等式中:it=natlog 1

问题在于,由于
^
的原因,您的输入需要是一个
整数
,而由于
/
的原因,您的输入需要是一个
分数
。您可以通过对其中一个使用不同的运算符轻松解决此问题;例如,使用
**
而不是
^

<interactive>:1:8:
    Ambiguous type variable `t0' in the constraints:
      (Num t0) arising from the literal `1' at <interactive>:1:8
      (Integral t0) arising from a use of `natlog' at <interactive>:1:1-6
      (Fractional t0) arising from a use of `natlog'
                      at <interactive>:1:1-6
    Probable fix: add a type signature that fixes these type variable(s)
    In the first argument of `natlog', namely `1'
    In the expression: natlog 1
    In an equation for `it': it = natlog 1
natlog x=直到条件计数(1,1,0)
哪里
cond(u,val,u)=val<0.001
计数(i,val,sum)=(i+1,(-x)**i/i,sum+val)

问题在于,由于
^
的原因,您的输入需要是一个
整数
,而由于
/
的原因,您的输入需要是一个
分数
。您可以通过对其中一个使用不同的运算符轻松解决此问题;例如,使用
**
而不是
^

<interactive>:1:8:
    Ambiguous type variable `t0' in the constraints:
      (Num t0) arising from the literal `1' at <interactive>:1:8
      (Integral t0) arising from a use of `natlog' at <interactive>:1:1-6
      (Fractional t0) arising from a use of `natlog'
                      at <interactive>:1:1-6
    Probable fix: add a type signature that fixes these type variable(s)
    In the first argument of `natlog', namely `1'
    In the expression: natlog 1
    In an equation for `it': it = natlog 1
natlog x=直到条件计数(1,1,0)
哪里
cond(u,val,u)=val<0.001
计数(i,val,sum)=(i+1,(-x)**i/i,sum+val)