【发布时间】:2016-05-19 13:34:34
【问题描述】:
我开始使用 Haskell 并创建了以下两个函数:
calcBmi :: ( RealFloat a ) => a -> a -> a -- Accepts two and returns one 'RealFloat' number.
calcBmi w h = w / h ^ (2 :: Integer) -- Stores argument one and two in w and h respectively and evaluates
outputBmi :: (RealFloat a) => a -> a -> String -- Accepts two RealFloats and returns string
outputBmi weight height = let bmi = calcBmi weight height in "Your BMI was calculated to " ++ bmi
当我尝试编译此代码时,出现以下异常
无法将预期类型“[Char]”与实际类型“a”匹配
在'(++)'的第二个参数中,即'bmi'
我对这个错误的含义感到困惑,更不用说如何修复代码以正确编译。我只能假设它与“bmi”变量的类型有关。
如果有人可以帮助初学者,将不胜感激。如果您在代码中发现其他问题(或者如果我使用了错误的术语),请随时告诉我。
【问题讨论】:
标签: haskell