-2
所以我試圖瞭解教程learnyouahaskell這個函數,它似乎並沒有正常工作。據我所知,它應該在一個對列表中,並從這些對返回一個BMI列表。創建一個函數,需要一個對列表 - learnyouahaskell
calcBmis :: (RealFloat a) => [(a, a)] -> [a]
calcBmis xs = [bmi w h | (w, h) <- xs]
where bmi weight height = weight/height^2
每次我嘗試和運行這個輸入,calcBmis [(1,2),(2.4)]
功能,我得到這個錯誤:
<interactive>:77:1: error:
• Non type-variable argument in the constraint: Fractional (a, a)
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a. (Fractional (a, a), RealFloat a) => [a]
哎呀,錯過了錯字。接得好。 – Davislor
哇......這很尷尬......謝謝! – humbleCoder