Copyright | (c) 2018-2020 Kowainik |
---|---|
License | MPL-2.0 |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
This module contains type aliases for memory data units. According to the
official standard, there exist two naming conventions for memory units. Standard
measure prefixes are multipliers of 10
. But there are alternative prefixes
which end with bi
and they are represented as powers of 2
. The difference
can be displayed in the following table:
Name | Multipliers | In bytes |
---|---|---|
Kilobyte | \( 10 ^ 3 \) | 1000 |
Kibibyte | \( 2 ^ {10} \) | 1024 |
Megabyte | \( 10 ^ 6 \) | 1000000 |
Mebibyte | \( 2 ^ {20} \) | 1048576 |
Synopsis
- type Bit = 1
- type Nibble = 4
- type Byte = 8
- type Kilobyte = 1000 * Byte
- type Megabyte = 1000 * Kilobyte
- type Gigabyte = 1000 * Megabyte
- type Terabyte = 1000 * Gigabyte
- type Petabyte = 1000 * Terabyte
- type Exabyte = 1000 * Petabyte
- type Zettabyte = 1000 * Exabyte
- type Yottabyte = 1000 * Zettabyte
- type Kibibyte = 1024 * Byte
- type Mebibyte = 1024 * Kibibyte
- type Gibibyte = 1024 * Mebibyte
- type Tebibyte = 1024 * Gibibyte
- type Pebibyte = 1024 * Tebibyte
- type Exbibyte = 1024 * Pebibyte
- type Zebibyte = 1024 * Exbibyte
- type Yobibyte = 1024 * Zebibyte
- type family UnitSymbol (unit :: Nat) = (res :: Symbol) | res -> unit
- type KnownUnitSymbol (mem :: Nat) = KnownSymbol (UnitSymbol mem)
- unitSymbol :: forall (mem :: Nat). KnownUnitSymbol mem => String
Simple
Decimal
Binary
Unit symbols
type family UnitSymbol (unit :: Nat) = (res :: Symbol) | res -> unit Source #
Type-level function to map memory units multipliers to proper symbols.
>>>
: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"
Instances
type UnitSymbol 1 Source # | |
Defined in Membrain.Units type UnitSymbol 1 = "b" | |
type UnitSymbol 4 Source # | |
Defined in Membrain.Units type UnitSymbol 4 = "n" | |
type UnitSymbol 8 Source # | |
Defined in Membrain.Units type UnitSymbol 8 = "B" | |
type UnitSymbol 8000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000 = "kB" | |
type UnitSymbol 8192 Source # | |
Defined in Membrain.Units type UnitSymbol 8192 = "KiB" | |
type UnitSymbol 8000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000 = "MB" | |
type UnitSymbol 8388608 Source # | |
Defined in Membrain.Units type UnitSymbol 8388608 = "MiB" | |
type UnitSymbol 8000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000 = "GB" | |
type UnitSymbol 8589934592 Source # | |
Defined in Membrain.Units type UnitSymbol 8589934592 = "GiB" | |
type UnitSymbol 8000000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000000 = "TB" | |
type UnitSymbol 8796093022208 Source # | |
Defined in Membrain.Units type UnitSymbol 8796093022208 = "TiB" | |
type UnitSymbol 8000000000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000000000 = "PB" | |
type UnitSymbol 9007199254740992 Source # | |
Defined in Membrain.Units type UnitSymbol 9007199254740992 = "PiB" | |
type UnitSymbol 8000000000000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000000000000 = "EB" | |
type UnitSymbol 9223372036854775808 Source # | |
Defined in Membrain.Units type UnitSymbol 9223372036854775808 = "EiB" | |
type UnitSymbol 8000000000000000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000000000000000 = "ZB" | |
type UnitSymbol 9444732965739290427392 Source # | |
Defined in Membrain.Units type UnitSymbol 9444732965739290427392 = "ZiB" | |
type UnitSymbol 8000000000000000000000000 Source # | |
Defined in Membrain.Units type UnitSymbol 8000000000000000000000000 = "YB" | |
type UnitSymbol 9671406556917033397649408 Source # | |
Defined in Membrain.Units type UnitSymbol 9671406556917033397649408 = "YiB" |
type KnownUnitSymbol (mem :: Nat) = KnownSymbol (UnitSymbol mem) Source #
Constraint alias for KnownSymbol
calculated by UnitSymbol
.
unitSymbol :: forall (mem :: Nat). KnownUnitSymbol mem => String Source #
Term-level function to get value of the UnitSymbol
type family. Can be used
only with -XTypeApplications
.
>>>
unitSymbol @Terabyte
"TB">>>
unitSymbol @Yobibyte
"YiB"