mainIO
- Plays the same role as
main()
in C
Vaibhav Sagar
Result
+---------------------+ ^
| | |
| +----+
| |
| |
+------->+ +-------->
State in +---------------------+ State out
Inputs Results
+ + +---------------------+ ^ ^
| | | | | |
| +------>+ +-----+ |
+---------->+ +---------+
| |
+-----------+ +--------->
State in +---------------------+ State out
-- +----------------------------------------+ Result
-- | | ^
-- | +-------------+ +-------------+ | |
-- | | ------>+ +--------+
-- | | s1 | | s2 | |
-- +------------>+ ------>+ +-------->
-- State in | +-------------+ +-------------+ | State out
-- | |
-- +----------------------------------------+
thenST :: ST s a -> (a -> ST s b) -> ST s b
accumArray :: Ix i => (a -> b -> a) -> a -> (i, i) -> [(i, b)] -> Array i a
accumArray f z bnds ivs = runST $ do
a <- newArr bnds z
seqST (map (update a f) ivs)
freezeArr s
update a f (i, v) = do
x <- readArr a i
writeArr a i (f x v)
hist :: Ix i => (i, i) -> [i] -> Array i Int
hist bnds is = accumArray (+) 0 bnds [(i, 1) | i <- is, inRange bnds i]
binSort :: Ix i => (i,i) -> (a -> i) -> [a] -> Array i a
binSort bnds key vs = accumArray (flip (:)) [] bnds [(key v, v) | v <- vs]
main()
in C