Created
June 12, 2012 08:34
-
-
Save MgaMPKAy/2916206 to your computer and use it in GitHub Desktop.
thread example code in haskell
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
module Main where | |
import Control.Concurrent | |
import Control.Monad | |
import System.Exit | |
data Alarm = Alarm { | |
second :: Int, | |
message :: String | |
} | |
clock :: Alarm -> IO () | |
clock alarm = do | |
threadDelay $ (second alarm)* 1000000 | |
putStrLn $ message alarm | |
main :: IO () | |
main = do | |
input <- getLine | |
when (null input) $ exitSuccess | |
let inputs = words input | |
second = read $ head inputs | |
message = unwords $ tail inputs | |
forkIO $ clock $ Alarm second message | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment