创建一个列出对列表的函数 - 学习YouAhaskell



因此,我试图在教程学习Youahaskell中理解此功能,并且似乎无法正常工作。据我了解,它应该列入对的列表,并从这些对中返回BMI列表。

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.4"而不是"(2,4)"。运行" CalcBmis [(1,2),(2,4)]"应该起作用。

最新更新