我想列出0.1
从-150
到的每一个数字150
。
为此,我创建了一个列表,然后尝试将分数乘法 lambda 映射到其上,如下所示:
let indices = [-1500,-1499..1500]
let grid = map (\x -> 0.1 *x) indices
这使得 ghci 吐出一个错误。
另一方面,这两个都可以正常工作:
let a = 0.1*2
和
let grid = map (\x -> 2 *x) indices
这里发生了什么?为什么仅当应用于带有地图的列表时,Num 乘以小数才会失败?
编辑:我得到的错误是:
No instance for (Fractional Integer)
arising from the literal `0.1'
Possible fix: add an instance declaration for (Fractional Integer)
In the first argument of `(*)', namely `0.1'
In the expression: 0.1 * x
In the first argument of `map', namely `(\ x -> 0.1 * x)'