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

Nic*_*ick 2 floating-point int haskell

我需要使用该map函数来获得例如pence到磅的转换.抱歉这个愚蠢的问题..但我是初学者.

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

pounds :: [Int] -> [Float]
pounds = map del 
Run Code Online (Sandbox Code Playgroud)

我收到这个错误..

*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
Run Code Online (Sandbox Code Playgroud)

Dan*_*her 8

看来你打字了

ghci> pounds 45
Run Code Online (Sandbox Code Playgroud)

在提示.但是要求pounds列表(of Int)作为其参数.你应该使用

ghci> del 45
Run Code Online (Sandbox Code Playgroud)

那里,或

ghci> pounds [45]
Run Code Online (Sandbox Code Playgroud)

由于整数文字有一个隐含的fromInteger,GHC试图找到转换fromInteger :: Integer -> [Int],这需要一个instance Num [Int],但它找不到,这是它报告的错误.