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 24.16: | 0.9.1 |
| Stackage Nightly 2025-10-24: | 0.9.1 |
| Latest on Hackage: | 0.9.1 |
safe-money-0.9.1@sha256:400e601b60ee8e6e2ff79cc942124540686e8e97dd50af930b7f675d27a3b132,2477Module 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:
FromJSONandToJSONinstances (from the aeson library). -
safe-money-cereal:
Serializeinstances (from the cereal library). -
safe-money-serialise:
Serialiseinstances (from the serialise library). -
safe-money-store:
Storeinstances (from the store library). -
safe-money-xmlbf:
FromXmlandToXmlinstances (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
xxxToDecimaldocs. See issue #45. -
Add
someXxxToDecimal. See issue #44.
Version 0.8
-
COMPILER ASSISTED BREAKING CHANGE. Introduced
DecimalConf, which all of thexxxToDecimalandxxxFromDecimalare now using. This concentrates all decimal rendering and parsing settings in a single place, and more importantly, it makes all of thexxxToDecimalreturn aTextvalue directly, rather than aMaybe Text. In turn,Separatorshas been introduced for configuring decimal and thousands separators. See issue #30. -
COMPILER ASSISTED BREAKING CHANGE. The
Scaletype family was renamed toUnitScale. -
COMPILER ASSISTED BREAKING CHANGE. Previous instances of the
Scaletype family where thecurrencyand theunitwere 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
Scalehas been introduced. This datatype replaces term-level uses ofRationalto 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-moneynow live in different libraries so that downstream packages can avoid using Cabal flags to specify dependencies. -
COMPILER ASSISTED BREAKING CHANGE.
FromJSONandToJSON(fromaeson) instances are not exported from thesafe-moneylibrary anymore. Instead, you are now expected to depend on the vettedsafe-money-aesonlibrary and importMoney.Aesonto get the relevant instances. These instances are exactly the same ones previously exported bysafe-money. As a consequence of this change, theaesonCabal flag insafe-moneyand the optional dependency onaesonwere removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Store(fromstore) instances are not exported from thesafe-moneylibrary anymore. Instead, you are now expected to depend on the vettedsafe-money-storelibrary and importMoney.Storeto get the relevant instances. These instances are exactly the same ones previously exported bysafe-money. As a consequence of this change, thestoreCabal flag insafe-moneyand the optional dependency onserialisewere removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Serialise(fromserialise) instances are not exported from thesafe-moneylibrary anymore. Instead, you are now expected to depend on the vettedsafe-money-serialiselibrary and importMoney.Serialiseto get the relevant instances. These instances are exactly the same ones previously exported bysafe-money. As a consequence of this change, theserialiseCabal flag insafe-moneyand the optional dependency onserialisewere removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
Serialize(fromcereal) instances are not exported from thesafe-moneylibrary anymore. Instead, you are now expected to depend on the vettedsafe-money-cereallibrary and importMoney.Serializeto get the relevant instances. These instances are exactly the same ones previously exported bysafe-money. As a consequence of this change, thecerealCabal flag insafe-moneyand the optional dependency oncerealwere removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
FromXmlandToXml(fromxmlbf) instances are not exported from thesafe-moneylibrary anymore. Instead, you are now expected to depend on the vettedsafe-money-xmlbflibrary and importMoney.Aesonto get the relevant instances. These instances are exactly the same ones previously exported bysafe-money. As a consequence of this change, thexmlbfCabal flag insafe-moneyand the optional dependency onxmlbfwere removed, which simplifies downstream packaging. -
COMPILER ASSISTED BREAKING CHANGE.
hashableandvector-spaceare now mandatory dependencies ofsafe-money.Hashable,VectorSpaceandAdditiveGroupinstances for the varioussafe-moneydatatypes are now exported fromMoney. Thehashableandvector-spaceCabal flags are now gone. -
Arbitraryinstances (from theQuickCheckpackages) for the varioussafe-moneydatatypes are now exported fromMoney.QuickCheckis now a mandatory dependency ofsafe-money.
Version 0.6
-
COMPILER ASSISTED BREAKING CHANGE.
denseToDecimalnow takes a positiveRationalrather than aProxy scale. -
COMPILER ASSISTED BREAKING CHANGE.
denseFromDecimalanddiscreteFromDecimalnow take a positiveRationalscale, like theirxxxToDecimalcounterparts. -
COMPILE ASSISTED BREAKING CHANGE.
binary,deepseqandtextare 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.
Textreplaced the use ofStringin the public API. For example,denseCurrencynow 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,ceilingandtruncatefunctions were replaced by a singlediscreteFromDensefunction taking an argument of typeApproximation(Round,Floor,CeilingorTruncate) as an argument. -
COMPILER ASSISTED BREAKING CHANGE. The
fromDiscretefunction was renamed todenseFromDiscrete. -
COMPILER ASSISTED BREAKING CHANGE. The
fromExchangeRatefunction was renamed toexchangeRateToRational. -
COMPILER ASSISTED BREAKING CHANGE. The
flipExchangeRatefunction was renamed toexchangeRateRecip. -
COMPILER ASSISTED BREAKING CHANGE. The
Denseis not an instance ofFractionalanymore becauserecipand/could potentially crash. -
Introduced new functions for rendering and parsing decimal reperesentations of monetary amounts:
denseCurrency,discreteCurrency,denseFromDecimal,denseToDecimal,discreteFromDecimal,exchangeRateFromDecimal,exchangeRateToDecimal. -
Introduced optional
AdditiveGroupandVectorSpacegroup instances forDenseandDiscrete. These type-classes come from thevector-spacelibrary and they can be enabled or disabled via thevector-spaceCabal flag, which is enabled by default. -
Introduced
discreteconstructor which behaves just likefromInteger. -
Introduced the
dense'constructor as an unsafe but convenient version ofdense. -
The
ErrScaleNonCanonicaltype is now exported. -
The
Money.Internalmodule is now exposed, but hidden from the Haddock documentation. -
New scale:
"BTC" "millibitcoin". -
Added many tests.
Version 0.4.1
ExchangeRateis now aCategory.
Version 0.4
-
BREAKING CHANGE REQUIRING HUMAN INTERVENTION. The JSON serializations for all of
Dense,SomeDense,Discrete,SomeDiscrete,ExchangeRateandSomeExchangeRatechanged. TheFromJSONinstances are backwards compatible with the old serializations, but theToJSONinstances 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 theToJSONinstance, please update your code. -
COMPILER ASSISTED BREAKING CHANGE. Changed the
Repsuffix for aSomeprefix Everywhere. For example,DenseRepwas renamed toSomeDense. -
COMPILER ASSISTED BREAKING CHANGE. Replaced the
someDenseAmountNumeratorandsomeDenseAmountDenominatorIntegerswith a singlesomeDenseAmountRationalnumber. Similarly forsomeDiscreteScaleandsomeExchangeRateRate. ThemkSomeDense,someDiscreteScaleandmkSomeDensealso take aRationalnow. -
COMPILER ASSISTED BREAKING CHANGE. The
truncate,floor,celingandroundfunctions now return just0as a reminder if there’s no significant reminder, instead ofNothing. -
Added instances for
serialise. -
Added instances for
xmlbf. -
Fixed
Showinstances so that surrounding parentheses are included when necessary. -
New currencies: Ripple, Litecoin, Ada, Monero.
Version 0.3
-
COMPILER ASSISTED BREAKING CHANGE. The
Data.Moneymodule was renamed toMoney. -
COMPILER ASSISTED BREAKING CHANGE. The
Data.Money.Internalmodule is not exposed anymore. All of its contents are now exported from theMoneymodule. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
discreteReptotoDiscreteRep. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
denseReptotoDenseRep. -
COMPILER ASSISTED BREAKING CHANGE. Renamed
exchangeRateReptotoExchangeRateRep. -
COMPILER ASSISTED BREAKING CHANGE. Renamed Iceleandic currency
"eyir"to"eyrir" -
Remove upper bound constraints from all dependencies except
base. -
Made dependency on
storeoptional 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
Storeinstances and test them.
Version 0.1
- Initial release.