Haskell的简短地图

时间:2015-11-08 13:45:03

标签: haskell

我有一个函数penceToPounds :: [Int] -> [Float]可将笔数转换为磅。我必须使用map

来解决这个问题

有一条很长的路要走:

penceToPounds xs = map ptp xs
                   where ptp x = fromIntegral x / 100

如果我想编写较短版本的函数,如何包含fromIntegral,例如:

penceToPounds = map (`div` 100)

1 个答案:

答案 0 :(得分:3)

以无点样式编写函数:

penceToPounds = map ( (/ 100) . fromIntegral )

penceToPounds = map $ (/ 100) . fromIntegral