我需要計算列表中的值之間的值,即[135,136,138,140]將計數135-136,136-138,138-140之間的所有數字。輸入列表[135.2,135.3,137,139]將使用類型[Float] [Float] [Int]輸出[2,1,1]。到目前爲止,我有:計數箱的集合中的頻率
heightbetween :: Float -> Float -> [Float] -> Int
heightbetween _ _ [] = 0
heightbetween n s (x:xs)
| (n < x) && (s > x) = 1 + (heightbetween n s xs)
| otherwise = heightbetween n s xs
count :: [Float] -> [Float] -> [Int]
count [] [] = []
count [x,y] = [(x,y)]
count (x:y:ys) = (x,y):count (y:ys)
forEach fun lst = heightbetween op ([],lst)
where
op (start,[]) = Nothing
op (start,a:as) = Just (start++(fun a):as
,(start++[a],as))
forPairs fun lst lst2 = map (map fst)
$ forEach (\(a,b)->(fun a b,b))
$ zip lst lst2
@Eugene Sh。我如何計算大於140且小於135的值?它應該是模擬[從這裏開始,但我仍然得到同樣的錯誤 – caz 2014-11-28 14:51:18