{-# LANGUAGE TypeApplications #-}
module Micros
( Micros (..),
fromFixed,
Micros.div,
minus,
scale,
sleep,
)
where
import Control.Concurrent (threadDelay)
import Data.Coerce
import Data.Fixed
import Data.Word
newtype Micros = Micros {Micros -> Word64
unMicros :: Word64}
deriving stock (Micros -> Micros -> Bool
(Micros -> Micros -> Bool)
-> (Micros -> Micros -> Bool) -> Eq Micros
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Micros -> Micros -> Bool
$c/= :: Micros -> Micros -> Bool
== :: Micros -> Micros -> Bool
$c== :: Micros -> Micros -> Bool
Eq, Eq Micros
Eq Micros
-> (Micros -> Micros -> Ordering)
-> (Micros -> Micros -> Bool)
-> (Micros -> Micros -> Bool)
-> (Micros -> Micros -> Bool)
-> (Micros -> Micros -> Bool)
-> (Micros -> Micros -> Micros)
-> (Micros -> Micros -> Micros)
-> Ord Micros
Micros -> Micros -> Bool
Micros -> Micros -> Ordering
Micros -> Micros -> Micros
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Micros -> Micros -> Micros
$cmin :: Micros -> Micros -> Micros
max :: Micros -> Micros -> Micros
$cmax :: Micros -> Micros -> Micros
>= :: Micros -> Micros -> Bool
$c>= :: Micros -> Micros -> Bool
> :: Micros -> Micros -> Bool
$c> :: Micros -> Micros -> Bool
<= :: Micros -> Micros -> Bool
$c<= :: Micros -> Micros -> Bool
< :: Micros -> Micros -> Bool
$c< :: Micros -> Micros -> Bool
compare :: Micros -> Micros -> Ordering
$ccompare :: Micros -> Micros -> Ordering
$cp1Ord :: Eq Micros
Ord)
fromFixed :: Fixed E6 -> Micros
fromFixed :: Fixed E6 -> Micros
fromFixed =
(Integer -> Word64) -> Fixed E6 -> Micros
coerce @(Integer -> Word64) Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
div :: Micros -> Micros -> Micros
div :: Micros -> Micros -> Micros
div =
(Word64 -> Word64 -> Word64) -> Micros -> Micros -> Micros
coerce (Integral Word64 => Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
Prelude.div @Word64)
minus :: Micros -> Micros -> Micros
minus :: Micros -> Micros -> Micros
minus =
(Word64 -> Word64 -> Word64) -> Micros -> Micros -> Micros
coerce ((-) @Word64)
scale :: Int -> Micros -> Micros
scale :: Int -> Micros -> Micros
scale Int
n (Micros Word64
w) =
Word64 -> Micros
Micros (Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
* Word64
w)
sleep :: Micros -> IO ()
sleep :: Micros -> IO ()
sleep (Micros Word64
micros) =
Int -> IO ()
threadDelay (Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
micros)