0
這裏是我的代碼:混淆類型ghci中
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)]
我在假設我製作的清單是(Integer,Integer)
,但是不能在calcBmis
中處理,僅在Fractional
。任何想法如何解決這個問題?
美麗,謝謝 – Charana