eallik

Untitled

Apr 7th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Concurrent (threadDelay)
  2.  
  3. data Time = Micros Int | Millis Int | Seconds Int | Minutes Int | Hours Int
  4.   deriving Show
  5.  
  6. -- unit relationships
  7. inMicros = id
  8. inMillis = inMicros . (* 1000)
  9. inSeconds = inMillis . (* 1000)
  10. inMinutes = inSeconds . (* 60)
  11. inHours = inMinutes . (* 60)
  12.  
  13. toMicros time = case time of
  14.   (Micros  x) -> inMicros  x
  15.   (Millis  x) -> inMillis  x
  16.   (Seconds x) -> inSeconds x
  17.   (Minutes x) -> inMinutes x
  18.   (Hours   x) -> inHours   x
  19.  
  20. sleep x unit = threadDelay . fromIntegral . toMicros . unit $ x
  21.  
  22. dosleep = sleep 5 Micros
Advertisement
Add Comment
Please, Sign In to add comment