currency-convert-0.2.1.0: Typesafe currency conversion

Copyright(c) Tuomas Laakkonen 2016
LicenseBSD3
Maintainerpigworts2@gmail.com
StabilityExperimental
PortabilityNon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Data.Currency.Convert

Description

This module allows values of currency to be converted from one currency to another using exchange rates from various sources.

The basic operation for this module is as follows:

First, get a conversion function (with getDefaultConverter or getConverter):

>>> Converter convert <- getDefaultConverter

Then, construct some value of currency using the convenience functions, and convert it using the convert function you just got:

>>> convert (usd 100) :: EUR
90.0 eur

The result type of convert defines what currency the value will be converted into.

Synopsis

Documentation

newtype Converter Source

Converter is a newtype wrapper around the type of conversion functions to avoid ImpredicativeTypes in getConverter

Constructors

Converter (forall a b. (KnownSymbol a, KnownSymbol b) => Currency a -> Currency b) 

getConverter :: RateProvider -> IO Converter Source

getConverter takes a rate provider and returns a Converter in the IO monad. It is used like this:

>>> Converter convert <- getConverter provider

convert can then be used to convert between currencies:

>>> convert (usd 100) :: GBP
75.0 gbp

getDefaultConverter :: IO Converter Source

getDefaultConverter is like getConverter except no provider needs to be specified (defaultProvider is used).

unsafeCoerceCurrency :: Currency a -> Currency b Source

unsafeCoerceCurrency can be used to convert between currencies directly without using exchange rates. Only use this if you know the resulting currency is supported by your RateProvider

data Currency s Source

Currency is a wrapper around Double that has a phantom symbol type, allowing different currencies to be distinguished using type level literals.

To extract the value from a Currency value, use toRational from Real.

data RateProvider Source

RateProvider is used by getConverter to provide a conversion rate dictionary to the resulting conversion function. RateProvider has two fields, the name (:: String), and the action (:: IO RateDict). The name is used in error reporting, and the action is used to provide conversion rates when needed.

There are several prebuilt RateProviders - fixerIOProvider, backupProvider, localProvider, dictProvider and defaultProvider.

Constructors

RateProvider String (IO RateDict) 

newtype RateDict Source

RateDict is the type provided by a RateProvider. It is a mapping from currency codes to currency-to-euro conversion rates.

Constructors

RateDict [(String, Double)] 

defaultProvider :: RateProvider Source

This RateProvider is used by getDefaultConverter it first tries fixer.io and then resorts to the backup dictionary.

backupProvider :: RateProvider Source

This RateProvider has a hardcoded dictionary.

dictProvider :: String -> [(String, Double)] -> RateProvider Source

This RateProvider allows a dictionary to be provided.

localProvider :: FilePath -> RateProvider Source

This RateProvider takes a file path and returns a dictionary of rates from the file. The file must be in the form

    <name1> <rate1>
    <name2> <rate2>
    ...
   

fixerIOProvider :: RateProvider Source

This RateProvider uses the fixer.io API to return exchange rates updated daily by the European Central Bank.

(<|-|>) :: RateProvider -> RateProvider -> RateProvider infixr 9 Source

'(<|-|>)' combines two RateProviders to create a third. This provider tries to return the first providers result, but if an exception is raised, it returns the second providers result.

aud :: Double -> AUD Source

The Australian Dollar

bgn :: Double -> BGN Source

The Bulgarian Lev

brl :: Double -> BRL Source

The Brazillian Real

cad :: Double -> CAD Source

The Canadian Dollar

chf :: Double -> CHF Source

The Swiss Franc

cny :: Double -> CNY Source

The Yuan

czk :: Double -> CZK Source

The Czech Karuna

dkk :: Double -> DKK Source

The Danish Krone

gbp :: Double -> GBP Source

The Pound Sterling

hkd :: Double -> HKD Source

The Hong Kong Dollar

hrk :: Double -> HRK Source

The Croatian Kuna

huf :: Double -> HUF Source

The Forint

idr :: Double -> IDR Source

The Rupiah

ils :: Double -> ILS Source

The New Israeli Sheqel

inr :: Double -> INR Source

The Indian Rupee

jpy :: Double -> JPY Source

The Yen

krw :: Double -> KRW Source

The Won

mxn :: Double -> MXN Source

The Mexican Peso

myr :: Double -> MYR Source

The Malaysian Ringgit

nok :: Double -> NOK Source

The Norwegian Krone

nzd :: Double -> NZD Source

The New Zealand Dollar

php :: Double -> PHP Source

The Phillipine Peso

pln :: Double -> PLN Source

The Zloty

ron :: Double -> RON Source

The Romanian Leu

rub :: Double -> RUB Source

The Russian Ruble

sek :: Double -> SEK Source

The Swedish Krona

sgd :: Double -> SGD Source

The Singapore Dollar

thb :: Double -> THB Source

The Thai Baht

try :: Double -> TRY Source

The Turkish Lira

usd :: Double -> USD Source

The United States of America Dollar

zar :: Double -> ZAR Source

The Rand

eur :: Double -> EUR Source

The Euro

type AUD = Currency "aud" Source

The Australian Dollar

type BGN = Currency "bgn" Source

The Bulgarian Lev

type BRL = Currency "brl" Source

The Brazillian Real

type CAD = Currency "cad" Source

The Canadian Dollar

type CHF = Currency "chf" Source

The Swiss Franc

type CNY = Currency "cny" Source

The Yuan

type CZK = Currency "czk" Source

The Czech Karuna

type DKK = Currency "dkk" Source

The Danish Krone

type GBP = Currency "gbp" Source

The Pound Sterling

type HKD = Currency "hkd" Source

The Hong Kong Dollar

type HRK = Currency "hrk" Source

The Croatian Kuna

type HUF = Currency "huf" Source

The Forint

type IDR = Currency "idr" Source

The Rupiah

type ILS = Currency "ils" Source

The New Israeli Sheqel

type INR = Currency "inr" Source

The Indian Rupee

type JPY = Currency "jpy" Source

The Yen

type KRW = Currency "krw" Source

The Won

type MXN = Currency "mxn" Source

The Mexican Peso

type MYR = Currency "myr" Source

The Malaysian Ringgit

type NOK = Currency "nok" Source

The Norwegian Krone

type NZD = Currency "nzd" Source

The New Zealand Dollar

type PHP = Currency "php" Source

The Phillipine Peso

type PLN = Currency "pln" Source

The Zloty

type RON = Currency "ron" Source

The Romanian Leu

type RUB = Currency "rub" Source

The Russian Ruble

type SEK = Currency "sek" Source

The Swedish Krona

type SGD = Currency "sgd" Source

The Singapore Dollar

type THB = Currency "thb" Source

The Thai Baht

type TRY = Currency "try" Source

The Turkish Lira

type USD = Currency "usd" Source

The United States of America Dollar

type ZAR = Currency "zar" Source

The Rand

type EUR = Currency "eur" Source

The Euro