streamly/test/applicative.hs
2017-06-26 03:15:27 +05:30

18 lines
533 B
Haskell

{-# LANGUAGE FlexibleContexts #-}
import Control.Applicative ((<$>), (<*>), (<|>))
import Control.Monad.IO.Class (liftIO)
import System.IO
import Strands
main = do
hSetBuffering stdout LineBuffering
xs <- gather $ threads 5 $ do
x <- (,) <$> (event 1 <|> event 2) <*> (event 3 <|> event 4)
--x <- (,) <$> choose [1,2] <*> choose [3,4]
liftIO $ putStrLn $ show x
return x
putStrLn $ show xs
where
event n = async (do putStrLn ("event" ++ show n); return n :: IO Int)