Haskell Int到Float转换:Num[Int]没有实例

Haskell Int到Float转换:Num[Int]没有实例,haskell,floating-point,int,Haskell,Floating Point,Int,我需要使用map函数来获得例如便士到英镑的转换。 很抱歉问了这个愚蠢的问题。。但我是个初学者 del :: Int -> Float del x = ( fromIntegral x ) / 100 pounds :: [Int] -> [Float] pounds = map del 我得到了这个错误 *Main> pounds 45 <interactive>:90:8: No instance for (Num [Int]) ari

我需要使用
map
函数来获得例如便士到英镑的转换。 很抱歉问了这个愚蠢的问题。。但我是个初学者

del :: Int -> Float
del x =  ( fromIntegral x ) / 100

pounds :: [Int] -> [Float]
pounds = map del 
我得到了这个错误

*Main> pounds 45
<interactive>:90:8:
    No instance for (Num [Int])
      arising from the literal `45'
    Possible fix: add an instance declaration for (Num [Int])
    In the first argument of `pounds', namely `45'
    In the expression: pounds 45
    In an equation for it': it = pounds 45
*Main>45磅
:90:8:
没有(Num[Int])的实例
源于字面上的'45'
可能的修复方法:为(Num[Int])添加实例声明
在'pounds'的第一个参数中,即'45'
在表达式中:45磅
在一个公式中:it=45磅

英镑的参数必须是
Int
的列表,而不是孤立的
Int

试着用磅[45]来代替。

看起来你是在打字

ghci> pounds 45
在提示下。但是
lbs
需要一个列表(of
Int
)作为其参数。你应该使用

ghci> del 45
在那里,或者

ghci> pounds [45]

由于整数文本有一个隐式的
fromInteger
,GHC尝试查找转换
fromInteger::integer->[Int]
,这将需要一个
实例Num[Int]
,但它找不到,这就是它报告的错误。

仅对列表有效,但对数字使用它

pounds [45]
那就行了

通常,当编译器说它缺少一个实例时,通常意味着你的参数类型错误或缺少