簡單的函數:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints tps =
map (\tp -> (time tp, distance tp, speed tp)) $
filter (\tp -> rpm tp > 10000) tps
相同,但自由點,在可能的情況:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints =
map (\tp -> (time tp, distance tp, speed tp)) .
filter ((> 10000) . rpm)
使用衛兵:
processTrackPoints :: [TrackPoint] -> [(Integer, Float, Float)]
processTrackPoints ((TP rpm time distance speed) : t)
| rpm > 10000 = (time, distance, speed) : processTrackPoints t
| otherwise = processTrackPoints t
processTrackPoints _ = []
這就是所有,當然假設你有這樣正確定義的數據類型:
data TrackPoint =
TP {
rpm :: Integer,
time :: Integer,
distance :: Float,
speed :: Float
}
deriving (Show)
你試過了什麼?您能否提供一些具有相應輸出的示例輸入? – hammar 2013-04-28 17:21:42