Giter Site home page Giter Site logo

currency-convert's Introduction

currency-convert

Property Value
Module Data.Currency.Convert
Description Typesafe currency coversion using exchange rates from various sources.
Copyright © Tuomas Laakkonen 2016
License BSD3
Maintainer [email protected]
Stability Experimental
Portability Non-portable (GHC extensions)

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

Basic Operation

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.

Currency implements Num, Fractional and Real so the usual arithmetic operations are defined, and its value can be extracted with toRational.

Defining New Currencies

New currencies can be defined very simply:

    type NEW = Currency "new"
    new :: Real a => a -> NEW
    new = unsafeCoerceCurrency . fromRational . toRational

For some hypothetical currency new. These can be used like any other currency.

Defining New Rate Providers

A method for providing new sources of currency conversion rates is also provided:

Simply create a RateProvider. The arguments to RateProvider are as follows:

	RateProvider (name :: String) (getRates :: IO RateDict)

Where RateDict is just a list of (name :: String, rate :: Double) where rate is the conversion rate between the specified currency and the Euro.

Using Rate Providers

Different rate providers can be used by providing them as an argument to getConverter. You can also chain these using the combinator (<|-|>) which tries one rate provider before trying another if that fails (e.g online api followed by a local cache if that fails followed by a hardcoded dictionary).

currency-convert's People

Contributors

tuomas56 avatar walseb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.