Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides definitions for modeling and working with monetary values.
Synopsis
- data Money (s :: Nat) = Money {
- moneyDate :: !Day
- moneyCurrency :: !Currency
- moneyQuantity :: !(Quantity s)
- class MonadThrow m => Monetary m where
- convertM :: HasCallStack => KnownNat s => Currency -> Money s -> m (Money s)
- convertAsofM :: HasCallStack => KnownNat s => Day -> Currency -> Money s -> m (Money s)
- convert :: HasCallStack => MonadThrow m => KnownNat s => KnownNat k => Money s -> FxQuote k -> m (Money s)
- data MonetaryException where
- IncompatibleCurrenciesException :: HasCallStack => Currency -> Currency -> MonetaryException
- IncompatibleDatesException :: HasCallStack => Day -> Day -> MonetaryException
- InconsistentFxQuoteException :: forall (s :: Nat). (HasCallStack, KnownNat s) => FxQuote s -> MonetaryException
Documentation
data Money (s :: Nat) Source #
Type encoding for dated monetary values.
A dated monetary value is a 3-tuple of:
- a date when the monetary value is effective as of,
- the currency of the monetary value, and
- the quantity of the monetary value.
Money | |
|
Instances
Eq (Money s) Source # | |
Ord (Money s) Source # | |
KnownNat s => Show (Money s) Source # | |
Generic (Money s) Source # | |
KnownNat s => ToJSON (Money s) Source # | |
Defined in Haspara.Monetary | |
KnownNat s => FromJSON (Money s) Source # | |
type Rep (Money s) Source # | |
Defined in Haspara.Monetary type Rep (Money s) = D1 ('MetaData "Money" "Haspara.Monetary" "haspara-0.0.0.3-4zv1bokQoxCFAyBHZ5p8oz" 'False) (C1 ('MetaCons "Money" 'PrefixI 'True) (S1 ('MetaSel ('Just "moneyDate") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Day) :*: (S1 ('MetaSel ('Just "moneyCurrency") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Currency) :*: S1 ('MetaSel ('Just "moneyQuantity") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Quantity s))))) |
class MonadThrow m => Monetary m where Source #
Type encoding of a monetary context.
convertM :: HasCallStack => KnownNat s => Currency -> Money s -> m (Money s) Source #
Converts the given monetary value in one currency to another currency.
Note that the conversion is performed with an FX rate quotation as of the date of the given monetary value.
convertAsofM :: HasCallStack => KnownNat s => Day -> Currency -> Money s -> m (Money s) Source #
convert :: HasCallStack => MonadThrow m => KnownNat s => KnownNat k => Money s -> FxQuote k -> m (Money s) Source #
Attempts to convert the given Money
to another using the given FxQuote
value.
This function runs some guards before attempting to do the conversion:
- Base currency of the FX rate quotation should be the same as the currency
of the monetary value, throws
IncompatibleCurrenciesException
otherwise. - Date of the FX rate quotation should be equal to or greater than the date
of the monetary value, throws
IncompatibleDatesException
otherwise. - Rate of the FX rate quotation should be
1
if the base and quote quotation are same, throwsInconsistentFxQuoteException
otherwise.
data MonetaryException where Source #
Type encoding of exceptions thrown by the Monetary
module.
IncompatibleCurrenciesException | Indicates that we received a currency other than the expected currency. |
| |
IncompatibleDatesException | Indicates that we received a currency other than the expected currency. |
| |
InconsistentFxQuoteException | Indicates that we received a currency other than the expected currency. |
|
Instances
Show MonetaryException Source # | |
Defined in Haspara.Monetary showsPrec :: Int -> MonetaryException -> ShowS # show :: MonetaryException -> String # showList :: [MonetaryException] -> ShowS # | |
Exception MonetaryException Source # | |
Defined in Haspara.Monetary |