2017-09-23 98 views
-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] 

回答

2

你的第二个要素是 “2.4”,而不是 “(2,4)”。运行“calcBmis [(1,2),(2,4)]”应该有效。

+0

哎呀,错过了错字。接得好。 – Davislor

+0

哇......这很尴尬......谢谢! – humbleCoder