我正在通过Learn You A Haskell。我有以下功能:
//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(0, -25, 0, 0);
完美无缺。我现在正在制作列表理解,在哪里 期望的结果是这样的:
[(68,“体重不足”),(69,“ok”),(70,“ok”)]
这是我的ghci输入:
bmiTell :: (RealFloat a) => a -> a-> String
bmiTell weight height
| bmi <= skinny ="underweight"
| bmi <= normal = "ok"
| bmi <= fat = "fat"
| otherwise = "whale"
where
bmi = weight/height^2
(skinny,normal,fat)=(18.5, 25.0,30.0)
,输出
[(68.0, 'U'),(68.0, 'N'),(68.0, 'd'),(68.0, 'E'),(68.0, 'R'),(68.0, 'W' ),(68.0, 'E'),(68.0, 'I'),(68.0, 'G'),(68.0, 'H'),(68.0, 'T'),(69.0, 'U'), (69.0, 'N'),(69.0, 'd'),(69.0, 'E'),(69.0, 'R'),(69.0, 'W'),(69.0, 'E'),(69.0 , 'I'),(69.0, 'G'),(69.0, 'H'),(69.0, 'T'),(70.0, 'U'),(70.0, 'N'),(70.0” d '),(70.0,' E '),(70.0,' R '),(70.0,' W '),(70.0,' E '),(70.0,' I '),(70.0,' G” ),(70.0, 'H'),(70.0, 'T')]
我尝试将其设为(x,[y]),但我在“”而不是单引号中使用Chars得到相同的结果
答案 0 :(得分:3)
您只需使用map
功能:
map (\w -> (w, bmiTell w 185)) [68..70]
或者@ErikR提到,使用列表理解:
[ (x, bmiTell x 185) | x <- [68..70] ]