haspara-0.0.0.2: A library providing definitions to work with monetary values.
Safe HaskellNone
LanguageHaskell2010

Haspara.Monetary

Description

This module provides definitions for modeling and working with monetary values.

Synopsis

Documentation

data Money (s :: Nat) Source #

Type encoding for dated monetary values.

A dated monetary value is a 3-tuple of:

  1. a date when the monetary value is effective as of,
  2. the currency of the monetary value, and
  3. the quantity of the monetary value.

Constructors

Money 

Instances

Instances details
Eq (Money s) Source # 
Instance details

Defined in Haspara.Monetary

Methods

(==) :: Money s -> Money s -> Bool #

(/=) :: Money s -> Money s -> Bool #

Ord (Money s) Source # 
Instance details

Defined in Haspara.Monetary

Methods

compare :: Money s -> Money s -> Ordering #

(<) :: Money s -> Money s -> Bool #

(<=) :: Money s -> Money s -> Bool #

(>) :: Money s -> Money s -> Bool #

(>=) :: Money s -> Money s -> Bool #

max :: Money s -> Money s -> Money s #

min :: Money s -> Money s -> Money s #

KnownNat s => Show (Money s) Source # 
Instance details

Defined in Haspara.Monetary

Methods

showsPrec :: Int -> Money s -> ShowS #

show :: Money s -> String #

showList :: [Money s] -> ShowS #

Generic (Money s) Source # 
Instance details

Defined in Haspara.Monetary

Associated Types

type Rep (Money s) :: Type -> Type #

Methods

from :: Money s -> Rep (Money s) x #

to :: Rep (Money s) x -> Money s #

KnownNat s => ToJSON (Money s) Source # 
Instance details

Defined in Haspara.Monetary

KnownNat s => FromJSON (Money s) Source # 
Instance details

Defined in Haspara.Monetary

type Rep (Money s) Source # 
Instance details

Defined in Haspara.Monetary

type Rep (Money s) = D1 ('MetaData "Money" "Haspara.Monetary" "haspara-0.0.0.2-AxwfIaY3JAe5J0iuX9jCcl" '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

convertM

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 #

Converts the given monetary value in one currency to another currency as of the given date.

The rule is:

convertAsofM DATE2 CCY2 (Money DATE1 CCY1 QTY1) === convertM CCY2 (Money DATE2 CCY1 QTY1)

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:

  1. Base currency of the FX rate quotation should be the same as the currency of the monetary value, throws IncompatibleCurrenciesException otherwise.
  2. Date of the FX rate quotation should be equal to or greater than the date of the monetary value, throws IncompatibleDatesException otherwise.
  3. Rate of the FX rate quotation should be 1 if the base and quote quotation are same, throws InconsistentFxQuoteException otherwise.

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