这是我的代码:
n = [(a,b) | a <- [1..5],b <- [1..5]]
calcBmis xs = [bmi | (w, h) <- xs,let bmi = w / h ^ 2]
尝试申请calcBmis
时n
,我收到以下错误:
*Charana> calcBmis n
<interactive>:220:1:
No instance for (Fractional Integer)
arising from a use of ‘calcBmis’
In the expression: calcBmis n
In an equation for ‘it’: it = calcBmis n
在 ghci 中的进一步调查:
*Charana> :t calcBmis
calcBmis :: Fractional t => [(t, t)] -> [t]
*Charana> :t n
n :: [(Integer, Integer)]
我假设我生成的列表是 type (Integer,Integer)
,但不能在 中处理calcBmis
,它只接受Fractional
. 知道如何解决这个问题吗?