Safe Haskell | None |
---|---|
Language | Haskell2010 |
Representation of money, and bet quantities.
Synopsis
- data Amount (b :: Symbol) where
- UnsafeAmount :: (GoodScale (CurrencyScale b), KnownSymbol b) => {..} -> Amount b
- unsafeAmount :: (GoodScale (CurrencyScale b), KnownSymbol b) => Discrete' b (CurrencyScale b) -> Amount b
- class (Monoid b, Show b, Ord b) => IsBet b where
- smallestAmount :: b
- minus :: b -> b -> Maybe b
- add :: b -> b -> b
- mkAmount :: (GoodScale (CurrencyScale b), KnownSymbol b) => Discrete' b (CurrencyScale b) -> Maybe (Amount b)
- bigBlindToDense :: BigBlind -> Dense "BB"
- newtype BigBlind = BigBlind {
- unBigBlind :: Amount "BB"
Documentation
data Amount (b :: Symbol) where Source #
Amount
is the type used to represent amounts of money during a game of poker.
The internal representation of Amount
is a Discrete'
from the
safe-money package.
The exposed constructors for Amount
ensure that no Amount
can have a negative value.
The use of the safe-money
package allows for lossless conversion between currencies with
well-maintained support for type safety, serialisation, and currency conversions.
{-# Language TypeApplications #-} caseunsafeAmount
@"USD" (discrete
100) ofUnsafeAmount
x -> x -- x == discrete 100
UnsafeAmount | |
|
Instances
Eq (Amount b) Source # | |
Ord (Amount b) Source # | |
Defined in Poker.Amount | |
Show (Amount b) Source # | |
(GoodScale (CurrencyScale b), KnownSymbol b) => Semigroup (Amount b) Source # | |
(GoodScale (CurrencyScale b), KnownSymbol b) => Monoid (Amount b) Source # | |
Pretty (Amount b) Source # | |
Defined in Poker.Amount | |
(GoodScale (CurrencyScale b), KnownSymbol b) => IsBet (Amount b) Source # | |
unsafeAmount :: (GoodScale (CurrencyScale b), KnownSymbol b) => Discrete' b (CurrencyScale b) -> Amount b Source #
class (Monoid b, Show b, Ord b) => IsBet b where Source #
A type b
satisfies IsBet
if we know:
- A
Monoid
instance forb
. This allows us to construct a zero amount ofb
and toadd
two amounts ofb
together. - the smallest non-zero currency unit for
b
(smallestAmount
). For example, for USD the minimum currency amount is $0.01. - how to
add
twob
s. By default, this is theMonoid
instance's append forb
. - how to
minus
twob
s, which may fail (returningNothing
), if the resultingAmount
is negative.
Types that satisfy IsBet
are expected to have both Ord
and Show
instances, so that packages such as poker-game
can handle arbitrary new user bet types.
For an example instance of the IsBet
class, see Poker.BigBlind.
mkAmount :: (GoodScale (CurrencyScale b), KnownSymbol b) => Discrete' b (CurrencyScale b) -> Maybe (Amount b) Source #
Returns an Amount
from a Discrete'
so long as the given Discrete'
is non-negative.
>>>
mkAmount @"USD" 0
Just (UnsafeAmount {unAmount = Discrete "USD" 100%1 0})>>>
mkAmount @"USD" (-1)
Nothing
bigBlindToDense :: BigBlind -> Dense "BB" Source #
BigBlind
is the type describing poker chip amounts that are measured in big blinds.
The internal representation of BigBlind
is
. This module introduces
a new instance of Amount
BBCurrencyScale
(from the
safe-money package), which allows
translation from BigBlind to any valid currency in a lossless manner.
The small unit of a "BB" is a "bb", with 100 "bb"s in a "BB".
TODO include an API for translating from BigBlind to any safe-money currency, given
a Stake
.
Calculations in the safe-money package are done with Discrete and Dense types. Discrete values are used to describe a regular BigBlind value, such as 1.30bb. Dense values are used when calculating some complex (non-discrete) value such as one third of a big blind. When using the BigBlind type, it is best to do all calculation with Dense BB values and then convert back to a Discrete BB "bb" after all calculation has been completed:
BigBlind | |
|