Physical units of measure.
- data Seconds = Seconds Double
- data Bytes = Bytes Integer
- data IsUnits a where
- class HasUnits a b | a -> b where
- data WithUnits t where
- secs :: (Single Seconds -> c Single Seconds) -> Double -> WithUnits (c Single)
- bytes :: (Single Bytes -> c Single Bytes) -> Integer -> WithUnits (c Single)
- appWithUnits :: (forall units. Real units => t1 units -> b) -> WithUnits t1 -> b
- liftWithUnits :: (forall units. Real units => t1 units -> t2 units) -> WithUnits t1 -> WithUnits t2
- liftsWithUnits :: (forall units. Real units => [t1 units] -> [t2 units]) -> [WithUnits t1] -> [WithUnits t2]
- liftsWithUnits2 :: (forall units. Real units => [t1 units] -> [t2 units] -> [t3 units]) -> [WithUnits t1] -> [WithUnits t2] -> [WithUnits t3]
- class Collatable t where
- collateWithUnits :: Collatable c => [WithUnits (c Single)] -> [WithUnits (c [])]
The unit types
Seconds of time.
Bytes of data.
IsUnits
Represents the units used for some thing.
HasUnits
class HasUnits a b | a -> b whereSource
Determine the units used by the elements of some collection,
by inspecting the elements directly.
Returns Nothing
when applied to empty collections, as they have no units.
WithUnits wrappers
A wrapper type used to store data of varying physical units in a homogenous collection structure.
secs :: (Single Seconds -> c Single Seconds) -> Double -> WithUnits (c Single)Source
Helpful wrapper for constructing seconds-valued aspect data. Examples:
Time TotalWall `secs` 10 :: WithUnits (Aspect Single)
appWithUnits :: (forall units. Real units => t1 units -> b) -> WithUnits t1 -> bSource
Apply a function to unit-wrapped data
liftWithUnits :: (forall units. Real units => t1 units -> t2 units) -> WithUnits t1 -> WithUnits t2Source
Apply a function to unit-wrapped data.
liftsWithUnits :: (forall units. Real units => [t1 units] -> [t2 units]) -> [WithUnits t1] -> [WithUnits t2]Source
Transform values of each unit type as a group.
liftsWithUnits2 :: (forall units. Real units => [t1 units] -> [t2 units] -> [t3 units]) -> [WithUnits t1] -> [WithUnits t2] -> [WithUnits t3]Source
Transform values of each unit type as a group
Unit-preserving collation
class Collatable t whereSource
Collate some data, while preserving units.
collateWithUnits :: Collatable c => [WithUnits (c Single)] -> [WithUnits (c [])]Source
Collate some data.
collateWithUnits [ Time KernelCpu `secs` 5 , Time KernelCpu `secs` 10 , Time TotalWall `secs` 55 , Size ExeSize `bytes` 100884 , Time TotalWall `secs` 52 ] => [ WithSeconds (Time KernelCpu [Seconds 5.0, Seconds 10.0]) , WithSeconds (Time TotalWall [Seconds 55.0, Seconds 52.0]) , WithBytes (Size ExeSize [Bytes 1024])]