创建一个接受对列表的函数——learnyouahaskell

创建一个接受对列表的函数——learnyouahaskell,haskell,Haskell,所以我试图在教程learnyouahaskell中理解这个函数,但它似乎工作不正常。据我所知,它应该接收一个配对列表,并从这些配对中返回一个BMI列表 calcBmis :: (RealFloat a) => [(a, a)] -> [a] calcBmis xs = [bmi w h | (w, h) <- xs] where bmi weight height = weight / height ^ 2 第二个元素是“2.4”,而不是“(2,4)”。运行“

所以我试图在教程learnyouahaskell中理解这个函数,但它似乎工作不正常。据我所知,它应该接收一个配对列表,并从这些配对中返回一个BMI列表

calcBmis :: (RealFloat a) => [(a, a)] -> [a]  
calcBmis xs = [bmi w h | (w, h) <- xs]  
    where bmi weight height = weight / height ^ 2

第二个元素是“2.4”,而不是“(2,4)”。运行“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]