cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Data.Quantity

Description

Representation of values with an associated (free) unit of measure. Useful to disambiguate primitive types like Int or String which can be in different bases depending on the context.

Synopsis

Polymorphic Quantity

newtype Quantity (unit :: Symbol ) a Source #

Quantity (unit :: Symbol) a is a primitive a multiplied by an unit .

Example:

Instead of providing the unit implicitly as a comment, or a part of a name

>>> a :: Word32 -- in lovelace

we can write

>>> a :: Quantity "lovelace" Word32

which now has a different type from

>>> b :: Quantity "lovelace/byte" Word32

so mixing them up is more difficult.

The unit is mostly a phantom type, but it is also included in the ToJSON / FromJSON instances.

>>> Aeson.encode $ Quantity @"lovelace" 14
{"unit":"lovelace","quantity":14}

Constructors

Quantity

Fields

Instances

Instances details
Functor ( Quantity any) Source #
Instance details

Defined in Data.Quantity

Methods

fmap :: (a -> b) -> Quantity any a -> Quantity any b Source #

(<$) :: a -> Quantity any b -> Quantity any a Source #

Bounded a => Bounded ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Enum a => Enum ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Eq a => Eq ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Ord a => Ord ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Show a => Show ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Generic ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Associated Types

type Rep ( Quantity unit a) :: Type -> Type Source #

NFData a => NFData ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

Methods

rnf :: Quantity unit a -> () Source #

Hashable a => Hashable ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

( KnownSymbol unit, ToJSON a) => ToJSON ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

( KnownSymbol unit, FromJSON a) => FromJSON ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

( KnownSymbol unit, Buildable a) => Buildable ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

NoThunks a => NoThunks ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

ToText b => ToText ( Quantity sym b) Source #
Instance details

Defined in Data.Quantity

FromText b => FromText ( Quantity sym b) Source #
Instance details

Defined in Data.Quantity

type Rep ( Quantity unit a) Source #
Instance details

Defined in Data.Quantity

type Rep ( Quantity unit a) = D1 (' MetaData "Quantity" "Data.Quantity" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "Quantity" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getQuantity") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 a)))

Percentage

data Percentage Source #

Opaque Haskell type to represent values between 0 and 100 (incl).

Instances

Instances details
Bounded Percentage Source #
Instance details

Defined in Data.Quantity

Eq Percentage Source #
Instance details

Defined in Data.Quantity

Ord Percentage Source #
Instance details

Defined in Data.Quantity

Show Percentage Source #
Instance details

Defined in Data.Quantity

Generic Percentage Source #
Instance details

Defined in Data.Quantity

NFData Percentage Source #
Instance details

Defined in Data.Quantity

ToJSON Percentage Source #
Instance details

Defined in Data.Quantity

FromJSON Percentage Source #
Instance details

Defined in Data.Quantity

Buildable Percentage Source #
Instance details

Defined in Data.Quantity

NoThunks Percentage Source #
Instance details

Defined in Data.Quantity

PersistFieldSql Percentage Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField Percentage Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText Percentage Source #
Instance details

Defined in Data.Quantity

FromText Percentage Source #
Instance details

Defined in Data.Quantity

SymbolToField "protocolParametersDecentralizationLevel" ProtocolParameters Percentage Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

type Rep Percentage Source #
Instance details

Defined in Data.Quantity

type Rep Percentage = D1 (' MetaData "Percentage" "Data.Quantity" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' True ) ( C1 (' MetaCons "Percentage" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "getPercentage") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 Rational )))

clipToPercentage :: Rational -> Percentage Source #

Safe way to make a Percentage by clipping values that are out of bounds.

complementPercentage :: Percentage -> Percentage Source #

The complement is the amount that is missing to make it 100%.

Example: The complementPercentage of 0.7 is 0.3.

percentageToDouble :: Percentage -> Double Source #

Turn a Percentage to a Double (without any extra rounding.)