Skip to content

Instantly share code, notes, and snippets.

@MgaMPKAy
Created June 12, 2012 08:34
Show Gist options
  • Save MgaMPKAy/2916206 to your computer and use it in GitHub Desktop.
Save MgaMPKAy/2916206 to your computer and use it in GitHub Desktop.
thread example code in haskell
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