membrain-0.0.0.0: Type-safe memory units

Safe HaskellNone
LanguageHaskell2010

Membrain.Units

Contents

Description

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

Simple

type Bit = 1 Source #

type Nibble = 4 Source #

type Byte = 8 Source #

Decimal

type Kilobyte = 1000 * Byte Source #

type Megabyte = 1000 * Kilobyte Source #

type Gigabyte = 1000 * Megabyte Source #

type Terabyte = 1000 * Gigabyte Source #

type Petabyte = 1000 * Terabyte Source #

type Exabyte = 1000 * Petabyte Source #

type Zettabyte = 1000 * Exabyte Source #

Binary

type Kibibyte = 1024 * Byte Source #

type Mebibyte = 1024 * Kibibyte Source #

type Gibibyte = 1024 * Mebibyte Source #

type Tebibyte = 1024 * Gibibyte Source #

type Pebibyte = 1024 * Tebibyte Source #

type Exbibyte = 1024 * Pebibyte Source #

type Zebibyte = 1024 * Exbibyte Source #

type Yobibyte = 1024 * Zebibyte Source #

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 # 
Instance details

Defined in Membrain.Units

type UnitSymbol 1 = "b"
type UnitSymbol 4 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 4 = "n"
type UnitSymbol 8 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8 = "B"
type UnitSymbol 8000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000 = "kB"
type UnitSymbol 8192 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8192 = "KiB"
type UnitSymbol 8000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000 = "MB"
type UnitSymbol 8388608 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8388608 = "MiB"
type UnitSymbol 8000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000 = "GB"
type UnitSymbol 8589934592 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8589934592 = "GiB"
type UnitSymbol 8000000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000000 = "TB"
type UnitSymbol 8796093022208 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8796093022208 = "TiB"
type UnitSymbol 8000000000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000000000 = "PB"
type UnitSymbol 9007199254740992 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 9007199254740992 = "PiB"
type UnitSymbol 8000000000000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000000000000 = "EB"
type UnitSymbol 9223372036854775808 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 9223372036854775808 = "EiB"
type UnitSymbol 8000000000000000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000000000000000 = "ZB"
type UnitSymbol 9444732965739290427392 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 9444732965739290427392 = "ZiB"
type UnitSymbol 8000000000000000000000000 Source # 
Instance details

Defined in Membrain.Units

type UnitSymbol 8000000000000000000000000 = "YB"
type UnitSymbol 9671406556917033397649408 Source # 
Instance details

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"