我还是个新手,在创建一个函数时想要创建一个尽可能小的列表,它需要用到logBase x y。但我无法将logBase转换为可以在列表中使用的形式。
有什么建议吗?
我还是个新手,在创建一个函数时想要创建一个尽可能小的列表,它需要用到logBase x y。但我无法将logBase转换为可以在列表中使用的形式。
有什么建议吗?
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)]
Prelude> :t logBase
logBase :: (Floating a) => a -> a -> a
该函数返回浮点类中的一种类型,而程序中的其他变量(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]