, , . , , foldr.
-- | Accumulate function
--
acc :: Ord a => (t, a) -> ([t], a) -> ([t], a)
acc (i, x) z@(is, y) = case compare x y of
LT -> ([i], x) -- a new minimum! reinit the list of mins
EQ -> (i:is, y) -- equal minimum; add to the list of mins
_ -> z -- larger than min; accumulator unchanged
findPos = (Bounded a, Ord a) => [a] -> [Int]
findPos = fst . foldr acc ([], maxBound) . zip [(0 :: Int)..]
, zip ( ) , ([], maxBound) ( ), .
Bounded ( findPos Integer ), Maybe, .
Keeping track of the "minimum visible value", as well as the indices where this value was visible, allows you to build a stream processing machine that you could ask at any time, "what were the minimum values in the (possibly infinite) input stream so far.
source
share