小编use*_*996的帖子

身体质量指数计划在Haskell

我试着写在Haskell一个简单的程序,它可以决定一个人的身体质量指数.

这是我写的:

type Height = Float
type Weight = Float
type PeopleStats = [(String, Height, Weight)]
Run Code Online (Sandbox Code Playgroud)

和...

bmi :: Height -> Weight -> Float
bmi heightCm weightKg = weightKg/(heightCm)^2

healthy :: Height -> Weight -> Bool
healthy heightCm weightKg | 25 > index && 18 < index = True
                          | otherwise                = False
  where index = bmi heightCm weightKg
Run Code Online (Sandbox Code Playgroud)

到目前为止,"健康"功能可以计算某人的BMI,并且功能"healthyPeople"返回一个布尔语句,确定该人的BMI是否落入健康人认为正常的限度内.

我想写一个名为"healthyPeople"的函数.

healthyPeople :: PeopleStats -> [String]
Run Code Online (Sandbox Code Playgroud)

此函数需要获取PeopleStats列表并返回"健康"功能中被视为"健康"的人的名称(字符串)列表.

例如:

如果我输入,[("Lee", 65, 185), ("Wang", 170, 100), ("Tsu", 160, 120)]我将获得一个BMI返回true的人名的列表,形成"健康"中的布尔函数.

请帮忙 …

haskell

1
推荐指数
1
解决办法
778
查看次数

标签 统计

haskell ×1