| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Haspara.Monetary
Description
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.
Constructors
| Money | |
Fields
| |
Instances
| KnownNat s => FromJSON (Money s) Source # | |
| KnownNat s => ToJSON (Money s) Source # | |
Defined in Haspara.Monetary | |
| Generic (Money s) Source # | |
| KnownNat s => Show (Money s) Source # | |
| Eq (Money s) Source # | |
| Ord (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.8-83lIPqySeX32MZXT98KoZ2" '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.
Minimal complete definition
Methods
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
IncompatibleCurrenciesExceptionotherwise. - Date of the FX rate quotation should be equal to or greater than the date
of the monetary value, throws
IncompatibleDatesExceptionotherwise. - Rate of the FX rate quotation should be
1if the base and quote quotation are same, throwsInconsistentFxQuoteExceptionotherwise.
data MonetaryException where Source #
Type encoding of exceptions thrown by the Monetary module.
Constructors
| IncompatibleCurrenciesException | Indicates that we received a currency other than the expected currency. |
Fields
| |
| IncompatibleDatesException | Indicates that we received a currency other than the expected currency. |
Fields
| |
| InconsistentFxQuoteException | Indicates that we received a currency other than the expected currency. |
Fields
| |
Instances
| Exception MonetaryException Source # | |
Defined in Haspara.Monetary Methods toException :: MonetaryException -> SomeException # | |
| Show MonetaryException Source # | |
Defined in Haspara.Monetary Methods showsPrec :: Int -> MonetaryException -> ShowS # show :: MonetaryException -> String # showList :: [MonetaryException] -> ShowS # | |