-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Type-safe memory units -- -- membrain provides newtype wrapper for type-safe work -- with memory units -- --
-- newtype Memory (mem :: Nat) = Memory
-- { unMemory :: Natural
-- }
--
--
-- This data type stores memory unit value phantom type parameter which
-- is represented as type-level natural number. The ideas behind this
-- package are described in the following blog post:
--
-- -- >>> :kind! UnitSymbol Bit -- UnitSymbol Bit :: Symbol -- = "b" -- -- >>> :kind! UnitSymbol Byte -- UnitSymbol Byte :: Symbol -- = "B" -- -- >>> :kind! UnitSymbol Kilobyte -- UnitSymbol Kilobyte :: Symbol -- = "kB" -- -- >>> :kind! UnitSymbol Mebibyte -- UnitSymbol Mebibyte :: Symbol -- = "MiB" --type family UnitSymbol (unit :: Nat) = (res :: Symbol) | res -> unit -- | Constraint alias for KnownSymbol calculated by -- UnitSymbol. type KnownUnitSymbol (mem :: Nat) = KnownSymbol (UnitSymbol mem) -- | Term-level function to get value of the UnitSymbol type family. -- Can be used only with -XTypeApplications. -- --
-- >>> unitSymbol @Terabyte -- "TB" -- -- >>> unitSymbol @Yobibyte -- "YiB" --unitSymbol :: forall (mem :: Nat). KnownUnitSymbol mem => String -- | This module contains Memory data type and various utility -- functions: -- --
-- >>> memory @Byte 3
-- Memory {unMemory = 24}
--
memory :: forall (mem :: Nat). KnownNat mem => Natural -> Memory mem
-- | Convert memory from one unit to another.
--
-- Note: this changes only view, not model. So this operation has
-- zero runtime cost.
--
-- -- >>> showMemory $ toMemory @Kilobyte $ byte 100 -- "0.1kB" -- -- >>> showMemory $ toMemory @Kibibyte $ byte 100 -- "0.09765625KiB" --toMemory :: forall (to :: Nat) (from :: Nat). Memory from -> Memory to -- | This showMemory function shows a Memory value as -- Double along with the measure unit suffix. It shows -- Memory losslessly while used with standardized units of -- measurements. The following mathematical law is used to display -- Memory: -- -- A decimal representation written with a repeating final 0 is -- supposed to terminate before these zeros. Instead of -- 1.585000... one simply writes 1.585. The decimal is -- also called a terminating decimal. Terminating decimals represent -- rational numbers of the form <math>. If you use different forms -- of units then the show function for Memory hangs. -- --
-- >>> showMemory (Memory 22 :: Memory Byte) -- "2.75B" --showMemory :: forall mem. (KnownNat mem, KnownUnitSymbol mem) => Memory mem -> String -- | Inverse of showMemory. -- --
-- >>> readMemory @Byte "2.75B"
-- Just (Memory {unMemory = 22})
--
-- >>> readMemory @Bit "2.75B"
-- Nothing
--
readMemory :: forall (mem :: Nat). (KnownUnitSymbol mem, KnownNat mem) => String -> Maybe (Memory mem)
-- | Lossless Memory conversion to bits. Alias to unMemory.
--
-- -- >>> toBits $ byte 1 -- 8 -- -- >>> toBits $ kilobyte 1 -- 8000 --toBits :: Memory mem -> Natural -- | Lossless Memory conversion to rational number. -- --
-- >>> toRat $ byte 4 -- 4 % 1 -- -- >>> toRat $ toMemory @Byte $ bit 22 -- 11 % 4 --toRat :: forall (mem :: Nat). KnownNat mem => Memory mem -> Ratio Natural -- | Floor Memory unit to integral number. This function may lose -- some information, so use only when: -- --
-- >>> floor $ byte 4 -- 4 -- -- >>> floor $ toMemory @Byte $ bit 22 -- 2 --floor :: forall (n :: Type) (mem :: Nat). (Integral n, KnownNat mem) => Memory mem -> n -- | Returns the result of multiplication Natural with the given -- Memory value -- --
-- >>> memoryMul 2 (byte 4)
-- Memory {unMemory = 64}
--
memoryMul :: Natural -> Memory mem -> Memory mem
-- | Returns the result of comparison of two Memory values and the
-- difference between them as another Memory of the same unit.
--
--
-- >>> memoryDiff (bit 4) (bit 8)
-- (LT,Memory {unMemory = 4})
--
-- >>> memoryDiff (byte 8) (byte 4)
-- (GT,Memory {unMemory = 32})
--
-- >>> memoryDiff (kilobyte 2) (kilobyte 2)
-- (EQ,Memory {unMemory = 0})
--
memoryDiff :: Memory mem -> Memory mem -> (Ordering, Memory mem)
-- | Returns the result of addition of two Memory values casted to
-- the second memory unit.
--
--
-- >>> memoryPlus (bit 8) (megabyte 2)
-- Memory {unMemory = 16000008}
--
memoryPlus :: Memory mem1 -> Memory mem2 -> Memory mem2
-- | Retuns the result of division of two Memory values of any
-- units.
--
-- -- >>> memoryDiv (kilobyte 3) (byte 2) -- 1500 % 1 --memoryDiv :: Memory mem1 -> Memory mem2 -> Ratio Natural -- | Existential data type for Memorys. data AnyMemory MkAnyMemory :: Memory mem -> AnyMemory instance GHC.Classes.Ord (Membrain.Memory.Memory mem) instance GHC.Classes.Eq (Membrain.Memory.Memory mem) instance GHC.Generics.Generic (Membrain.Memory.Memory mem) instance GHC.Read.Read (Membrain.Memory.Memory mem) instance GHC.Show.Show (Membrain.Memory.Memory mem) instance GHC.Show.Show Membrain.Memory.AnyMemory instance GHC.Base.Semigroup (Membrain.Memory.Memory mem) instance GHC.Base.Monoid (Membrain.Memory.Memory mem) -- | This module implements smart constructors for creating values of type -- Memory. module Membrain.Constructors -- | Creates Memory in Bits from given Natural as the -- number of bits. -- --
-- >>> showMemory $ bit 42 -- "42b" --bit :: Natural -> Memory Bit -- | Creates Memory in Nibbles from given Natural as -- the number of nibbles. -- --
-- >>> showMemory $ nibble 42 -- "42n" --nibble :: Natural -> Memory Nibble -- | Creates Memory in Bytes from given Natural as the -- number of bytes. -- --
-- >>> showMemory $ byte 42 -- "42B" --byte :: Natural -> Memory Byte -- | Creates Memory in Kilobytes from given Natural as -- the number of kilobytes. -- --
-- >>> showMemory $ kilobyte 42 -- "42kB" --kilobyte :: Natural -> Memory Kilobyte -- | Creates Memory in Megabytes from given Natural as -- the number of megabytes. -- --
-- >>> showMemory $ megabyte 42 -- "42MB" --megabyte :: Natural -> Memory Megabyte -- | Creates Memory in Gigabytes from given Natural as -- the number of gigabytes. -- --
-- >>> showMemory $ gigabyte 42 -- "42GB" --gigabyte :: Natural -> Memory Gigabyte -- | Creates Memory in Terabytes from given Natural as -- the number of terabytes. -- --
-- >>> showMemory $ terabyte 42 -- "42TB" --terabyte :: Natural -> Memory Terabyte -- | Creates Memory in Petabytes from given Natural as -- the number of petabytes. -- --
-- >>> showMemory $ petabyte 42 -- "42PB" --petabyte :: Natural -> Memory Petabyte -- | Creates Memory in Exabytes from given Natural as -- the number of exabytes. -- --
-- >>> showMemory $ exabyte 42 -- "42EB" --exabyte :: Natural -> Memory Exabyte -- | Creates Memory in Zettabytes from given Natural -- as the number of zettabytes. -- --
-- >>> showMemory $ zettabyte 42 -- "42ZB" --zettabyte :: Natural -> Memory Zettabyte -- | Creates Memory in Yottabytes from given Natural -- as the number of yottabytes. -- --
-- >>> showMemory $ yottabyte 42 -- "42YB" --yottabyte :: Natural -> Memory Yottabyte -- | Creates Memory in Kibibytes from given Natural as -- the number of kibibytes. -- --
-- >>> showMemory $ kibibyte 42 -- "42KiB" --kibibyte :: Natural -> Memory Kibibyte -- | Creates Memory in Mebibytes from given Natural as -- the number of mebibytes. -- --
-- >>> showMemory $ mebibyte 42 -- "42MiB" --mebibyte :: Natural -> Memory Mebibyte -- | Creates Memory in Gibibytes from given Natural as -- the number of gibibytes. -- --
-- >>> showMemory $ gibibyte 42 -- "42GiB" --gibibyte :: Natural -> Memory Gibibyte -- | Creates Memory in Tebibytes from given Natural as -- the number of tebibytes. -- --
-- >>> showMemory $ tebibyte 42 -- "42TiB" --tebibyte :: Natural -> Memory Tebibyte -- | Creates Memory in Pebibytes from given Natural as -- the number of pebibytes. -- --
-- >>> showMemory $ pebibyte 42 -- "42PiB" --pebibyte :: Natural -> Memory Pebibyte -- | Creates Memory in Exbibytes from given Natural as -- the number of exbibytes. -- --
-- >>> showMemory $ exbibyte 42 -- "42EiB" --exbibyte :: Natural -> Memory Exbibyte -- | Creates Memory in Zebibytes from given Natural as -- the number of zebibytes. -- --
-- >>> showMemory $ zebibyte 42 -- "42ZiB" --zebibyte :: Natural -> Memory Zebibyte -- | Creates Memory in Yobibytes from given Natural as -- the number of yobibytes. -- --
-- >>> showMemory $ yobibyte 42 -- "42YiB" --yobibyte :: Natural -> Memory Yobibyte -- | This modules introduces more type-safe interface of some standard -- function to work with memory from base package. module Membrain.Base -- | For a handle which attached to a physical file, the function returns -- the size of that file in Bytes. -- -- Similar hFileSize from base but more type-safe: -- returns 'Memory Byte' instead of Integer. hFileSize :: Handle -> IO (Memory Byte) -- | Truncates the physical file with the handle to the given size in -- Bytes. -- -- Similar to hSetFileSize from base but more type-safe: -- it works with given 'Memory Byte' instead of Integer. -- -- NOTE: This function makes floor under the hood, so be -- careful when working with the smaller units. hSetFileSize :: Handle -> Memory Byte -> IO () -- | Returns the number of Bits in the type of the argument. The -- actual value of the argument is ignored. Returns Nothing for -- types that do not have a fixed bitsize, like Integer. -- -- Type safe version of the bitSizeMaybe function. -- --
-- >>> bitSizeMaybe (0 :: Int)
-- Just (Memory {unMemory = 64})
--
-- >>> bitSizeMaybe (0 :: Integer)
-- Nothing
--
bitSizeMaybe :: Bits a => a -> Maybe (Memory Bit)
-- | Return the number of bits in the type of the argument. The actual
-- value of the argument is ignored.
--
-- Type safe version of the finiteBitSize function.
--
--
-- >>> finiteBitSize False
-- Memory {unMemory = 1}
--
-- >>> finiteBitSize (0 :: Int)
-- Memory {unMemory = 64}
--
finiteBitSize :: FiniteBits b => b -> Memory Bit
-- | Like sizeOf but returns type-safe 'Memory Byte' instead of the
-- Int which represents the amount of bytes.
--
-- Computes the storage requirements (in bytes) of the argument. The
-- value of the argument is not used.
--
--
-- >>> sizeOf True
-- Memory {unMemory = 32}
--
-- >>> sizeOf 'x'
-- Memory {unMemory = 32}
--
-- >>> sizeOf (0 :: Int)
-- Memory {unMemory = 64}
--
-- >>> sizeOf (0.0 :: Double)
-- Memory {unMemory = 64}
--
sizeOf :: Storable a => a -> Memory Byte
-- | Executes the computation, passing as argument a pointer to a
-- temporarily allocated block of memory of n Bytes. The
-- block of memory is sufficiently aligned for any of the basic foreign
-- types that fits into a memory block of the allocated size.
--
-- The memory is freed when the computation terminates (either normally
-- or via an exception), so the passed pointer must not be used after
-- this.
--
-- Similar to allocaBytes but receives Bytes instead of
-- Int.
allocaBytes :: Memory Byte -> (Ptr a -> IO b) -> IO b
-- | Allocates a block of memory of the given number of Bytes. The
-- block of memory is sufficiently aligned for any of the basic foreign
-- types that fits into a memory block of the allocated size.
--
-- Similar to mallocBytes but receives Bytes instead of
-- Int.
mallocBytes :: Memory Byte -> IO (Ptr a)
-- | Llike mallocBytes but memory is filled with Bytes of
-- value zero.
callocBytes :: Memory Byte -> IO (Ptr a)
-- | Type safe version of the reallocBytes function.
reallocBytes :: Ptr a -> Memory Byte -> IO (Ptr a)
-- | Type safe version of the mallocForeignPtrBytes function.
mallocForeignPtrBytes :: Memory Byte -> IO (ForeignPtr a)
-- | Type-safe memory units. This package has the following structure:
--
-- -- import qualified Membrain as Mem --module Membrain