safe-money
Type-safe and lossless encoding and manipulation of money, fiat currencies, crypto currencies and precious metals.
https://github.com/k0001/safe-money
LTS Haskell 22.39: | 0.9.1 |
Stackage Nightly 2024-10-31: | 0.9.1 |
Latest on Hackage: | 0.9.1 |
safe-money-0.9.1@sha256:400e601b60ee8e6e2ff79cc942124540686e8e97dd50af930b7f675d27a3b132,2477
Module documentation for 0.9.1
- Money
- Money.Internal
The Haskell safe-money
library offers type-safe and lossless encoding and
operations for monetary values in all world currencies, including fiat
currencies, precious metals and crypto-currencies.
Useful instances for the many types defined by safe-money
can be found
in these other libraries:
-
safe-money-aeson:
FromJSON
andToJSON
instances (from the aeson library). -
safe-money-cereal:
Serialize
instances (from the cereal library). -
safe-money-serialise:
Serialise
instances (from the serialise library). -
safe-money-store:
Store
instances (from the store library). -
safe-money-xmlbf:
FromXml
andToXml
instances (from the xmlbf library).
Changes
Version 0.9.1
-
Add approximation method
HalfAwayFromZero
, also known as “kaufmännisches Runden” in German speaking countries. See issue #55. -
Fix compilation with GHC 9. See issue #59.
-
Added
exchangeRate'
. See issue #61.
Version 0.9
- BREAKING CHANGE, POSSIBLY REQUIRING HUMAN INTERVENTION. Changed
UnitScale "BSD" "cent"
from(1, 1)
to(100, 1)
, changedUnitScale "HTG" "centime"
from(1, 1)
to(100, 1)
, changedUnitScale "MDL" "leu"
from(100, 1)
to(1, 1)
, and changedUnitScale "SBD" "dollar"
from(100, 1)
to(1, 1)
. The scales in question were wrong before. If you relied on these specific scales, for example, for serializing and storing amounts in a database, you will need to rescale your amounts.
Version 0.8.1
-
Fix decimal rendering of some small cent values (e.g.,
0.02
). See issue #45. -
Fixed
xxxToDecimal
docs. See issue #45. -
Add
someXxxToDecimal
. See issue #44.
Version 0.8
-
COMPILER ASSISTED BREAKING CHANGE. Introduced
DecimalConf
, which all of thexxxToDecimal
andxxxFromDecimal
are now using. This concentrates all decimal rendering and parsing settings in a single place, and more importantly, it makes all of thexxxToDecimal
return aText
value directly, rather than aMaybe Text
. In turn,Separators
has been introduced for configuring decimal and thousands separators. See issue #30. -
COMPILER ASSISTED BREAKING CHANGE. The
Scale
type family was renamed toUnitScale
. -
COMPILER ASSISTED BREAKING CHANGE. Previous instances of the
Scale
type family where thecurrency
and theunit
were the same (e.g.,Scale "USD" "USD"
), intended to convey a canonical scale for the currency, are now written asCurrencyScale currency
(e.g.,CurrencyScale "USD"
). -
COMPILER ASSISTED BREAKING CHANGE. A new datatype called
Scale
has been introduced. This datatype replaces term-level uses ofRational
to convey the scale of a discrete monetary amount. The rationale for this, beyond improved type errors, is that checking for the scale’s validity can be done at a single place (namely, the newscaleFromRational
), rather than everywhere a term-level scale was expected as input. See issue #43. -
Added new approximation method
HalfEven
, also known as “Bankers rounding”. See issue #42. -
New currencies: VES (see issue #33), UYW.
Version 0.7.1
-
Fixed compilation with GHC 8.6.
-
Fixed an issue when rendering decimal values smaller than the smallest possible fractional part. See issue #39.
Version 0.7
-
IMPORTANT. All of the changes in this release are fully backwards compatible. What happens in this release is that many instances previously exported by
safe-money
now live in different libraries so that downstream packages can avoid using Cabal flags to specify dependencies. -
COMPILER ASSISTED BREAKING CHANGE.
FromJSON
andToJSON
(fromaeson
) instances are not exported from thesafe-money
library anymore. Instead, you are now expected to depend on the vettedsafe-money-aeson
library and importMoney.Aeson
to get the relevant instances. These instances are exactly the same ones previously exported bysafe-money
. As a consequence of this change, theaeson
Cabal flag insafe-money
and the optional dependency onaeson
were removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Store
(fromstore
) instances are not exported from thesafe-money
library anymore. Instead, you are now expected to depend on the vettedsafe-money-store
library and importMoney.Store
to get the relevant instances. These instances are exactly the same ones previously exported bysafe-money
. As a consequence of this change, thestore
Cabal flag insafe-money
and the optional dependency onserialise
were removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Serialise
(fromserialise
) instances are not exported from thesafe-money
library anymore. Instead, you are now expected to depend on the vettedsafe-money-serialise
library and importMoney.Serialise
to get the relevant instances. These instances are exactly the same ones previously exported bysafe-money
. As a consequence of this change, theserialise
Cabal flag insafe-money
and the optional dependency onserialise
were removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Serialize
(fromcereal
) instances are not exported from thesafe-money
library anymore. Instead, you are now expected to depend on the vettedsafe-money-cereal
library and importMoney.Serialize
to get the relevant instances. These instances are exactly the same ones previously exported bysafe-money
. As a consequence of this change, thecereal
Cabal flag insafe-money
and the optional dependency oncereal
were removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
FromXml
andToXml
(fromxmlbf
) instances are not exported from thesafe-money
library anymore. Instead, you are now expected to depend on the vettedsafe-money-xmlbf
library and importMoney.Aeson
to get the relevant instances. These instances are exactly the same ones previously exported bysafe-money
. As a consequence of this change, thexmlbf
Cabal flag insafe-money
and the optional dependency onxmlbf
were removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
hashable
andvector-space
are now mandatory dependencies ofsafe-money
.Hashable
,VectorSpace
andAdditiveGroup
instances for the varioussafe-money
datatypes are now exported fromMoney
. Thehashable
andvector-space
Cabal flags are now gone. -
Arbitrary
instances (from theQuickCheck
packages) for the varioussafe-money
datatypes are now exported fromMoney
.QuickCheck
is now a mandatory dependency ofsafe-money
.
Version 0.6
-
COMPILER ASSISTED BREAKING CHANGE.
denseToDecimal
now takes a positiveRational
rather than aProxy scale
. -
COMPILER ASSISTED BREAKING CHANGE.
denseFromDecimal
anddiscreteFromDecimal
now take a positiveRational
scale, like theirxxxToDecimal
counterparts. -
COMPILE ASSISTED BREAKING CHANGE.
binary
,deepseq
andtext
are now mandatory dependencies since they are included with the standard GHC distribution. Thus, the tags for disabling them have been removed. -
COMPILE ASSISTED BREAKING CHANGE.
Text
replaced the use ofString
in the public API. For example,denseCurrency
now returnsText
, instead ofString
. This change doesn’t break backwards compatibilility with binary serializations. -
Introduced a new function
discreteToDecimal
. -
Added tests to ensure backwards compatibility of serializations.
Version 0.5
-
COMPILER ASSISTED BREAKING CHANGE. The
round
,floor
,ceiling
andtruncate
functions were replaced by a singlediscreteFromDense
function taking an argument of typeApproximation
(Round
,Floor
,Ceiling
orTruncate
) as an argument. -
COMPILER ASSISTED BREAKING CHANGE. The
fromDiscrete
function was renamed todenseFromDiscrete
. -
COMPILER ASSISTED BREAKING CHANGE. The
fromExchangeRate
function was renamed toexchangeRateToRational
. -
COMPILER ASSISTED BREAKING CHANGE. The
flipExchangeRate
function was renamed toexchangeRateRecip
. -
COMPILER ASSISTED BREAKING CHANGE. The
Dense
is not an instance ofFractional
anymore becauserecip
and/
could potentially crash. -
Introduced new functions for rendering and parsing decimal reperesentations of monetary amounts:
denseCurrency
,discreteCurrency
,denseFromDecimal
,denseToDecimal
,discreteFromDecimal
,exchangeRateFromDecimal
,exchangeRateToDecimal
. -
Introduced optional
AdditiveGroup
andVectorSpace
group instances forDense
andDiscrete
. These type-classes come from thevector-space
library and they can be enabled or disabled via thevector-space
Cabal flag, which is enabled by default. -
Introduced
discrete
constructor which behaves just likefromInteger
. -
Introduced the
dense'
constructor as an unsafe but convenient version ofdense
. -
The
ErrScaleNonCanonical
type is now exported. -
The
Money.Internal
module is now exposed, but hidden from the Haddock documentation. -
New scale:
"BTC" "millibitcoin"
. -
Added many tests.
Version 0.4.1
ExchangeRate
is now aCategory
.
Version 0.4
-
BREAKING CHANGE REQUIRING HUMAN INTERVENTION. The JSON serializations for all of
Dense
,SomeDense
,Discrete
,SomeDiscrete
,ExchangeRate
andSomeExchangeRate
changed. TheFromJSON
instances are backwards compatible with the old serializations, but theToJSON
instances will only generate the new format, which is the same as the old format except the leading strings"Dense"
,"Discrete"
and"ExchangeRate"
, respectively, are not present in the rendered JSON array anymore. So, if you were manually relying on theToJSON
instance, please update your code. -
COMPILER ASSISTED BREAKING CHANGE. Changed the
Rep
suffix for aSome
prefix Everywhere. For example,DenseRep
was renamed toSomeDense
. -
COMPILER ASSISTED BREAKING CHANGE. Replaced the
someDenseAmountNumerator
andsomeDenseAmountDenominator
Integers
with a singlesomeDenseAmount
Rational
number. Similarly forsomeDiscreteScale
andsomeExchangeRateRate
. ThemkSomeDense
,someDiscreteScale
andmkSomeDense
also take aRational
now. -
COMPILER ASSISTED BREAKING CHANGE. The
truncate
,floor
,celing
andround
functions now return just0
as a reminder if there’s no significant reminder, instead ofNothing
. -
Added instances for
serialise
. -
Added instances for
xmlbf
. -
Fixed
Show
instances so that surrounding parentheses are included when necessary. -
New currencies: Ripple, Litecoin, Ada, Monero.
Version 0.3
-
COMPILER ASSISTED BREAKING CHANGE. The
Data.Money
module was renamed toMoney
. -
COMPILER ASSISTED BREAKING CHANGE. The
Data.Money.Internal
module is not exposed anymore. All of its contents are now exported from theMoney
module. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
discreteRep
totoDiscreteRep
. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
denseRep
totoDenseRep
. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
exchangeRateRep
totoExchangeRateRep
. -
COMPILER ASSISTED BREAKING CHANGE. Renamed Iceleandic currency
"eyir"
to"eyrir"
-
Remove upper bound constraints from all dependencies except
base
. -
Made dependency on
store
optional for the test suite, so that it can run on GHCJS.
Version 0.2
-
Cabal flags are now manual (
aeson
,binary
,bytes
,cereal
,deepseq
,hashable
). -
Backwards compatibility with GHC 7.10.
-
Fix
Store
instances and test them.
Version 0.1
- Initial release.