Six*_*ree 10 floating-point int haskell
我还是新手,并试图创建一个在函数中使用的列表,并希望尽可能小地保留它,这恰好是logBase x y.但是我无法将logBase变成我可以在此列表中使用的东西.
[1 ..(logBase xy)]
有什么建议?
Don*_*art 10
你没有发布你得到的类型错误,但我想它是这样的:
Prelude> let x = 2
Prelude> let y = 7
Prelude> [1 .. (logBase x y)]
<interactive>:1:7:
No instance for (Floating Integer)
arising from a use of `logBase' at <interactive>:1:7-17
Possible fix: add an instance declaration for (Floating Integer)
In the expression: (logBase x y)
In the expression: [1 .. (logBase x y)]
In the definition of `it': it = [1 .. (logBase x y)]
Run Code Online (Sandbox Code Playgroud)
问题是:
Prelude> :t logBase
logBase :: (Floating a) => a -> a -> a
Run Code Online (Sandbox Code Playgroud)
返回浮动类的类型,而在程序中的其它变量(1,"X","Y")是一体的类型.
我猜你想要一系列整数?
Prelude> :set -XNoMonomorphismRestriction
Prelude> let x = 2
Prelude> let y = 42
Prelude> [1 .. truncate (logBase x y)]
[1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)
使用截断,细长或地板.
| 归档时间: |
|
| 查看次数: |
19684 次 |
| 最近记录: |