Last active
March 11, 2016 03:49
-
-
Save mkscrg/817cfa97cf3894244fdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
module Main where | |
import Control.Concurrent | |
import Control.Monad | |
{- | |
ghc --make Main.hs | |
./Main | |
-} | |
main :: IO () | |
main = do | |
(inch :: Chan Int) <- (newChan :: IO (Chan Int)) | |
outch <- newChan | |
_ <- forkIO (fwdChan inch outch) | |
_ <- forkIO (printChan outch) | |
writeChan inch 1 | |
writeChan inch 2 | |
threadDelay 3000000 | |
fwdChan :: Chan a -> Chan a -> IO () | |
fwdChan inch outch = forever $ do | |
x <- readChan inch | |
writeChan outch x | |
printChan :: Show a => Chan a -> IO () | |
printChan chan = forever $ do | |
x <- readChan chan | |
y <- readChan chan | |
print x | |
print y | |
-- printChan chan = forever (readChan chan >>= (\x -> readChan >>= (\y -> print x >> print y))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment