Permalink
Browse files

Generic currency for convenience

  • Loading branch information...
1 parent f752508 commit 3a870b4dcf2342084ecf453164f7dc7daeb0af87 @jb55 committed Apr 4, 2012
Showing with 30 additions and 22 deletions.
  1. +13 −10 Data/Money.lhs
  2. +17 −12 README.md
View
@@ -8,12 +8,12 @@ Data.Money
> , HasSign(..)
> , Sign(..)
> , Position(..)
-> , leftSign
-> , rightSign
+> , leftSign, rightSign
> , currency
> , money
-> , USD, CAD, EUR
-> , usd
+> , fm
+> , USD, CAD, EUR, GenericC
+> , usd, rateOf
> ) where
> import Data.Default
@@ -196,6 +196,9 @@ Misc
> precision :: Word8
> precision = 6
+> rateOf :: Double -> GenericC
+> rateOf = GenericC
+
> fm :: RealFrac f => f -> Decimal
> fm = realFracToDecimal precision
@@ -239,12 +242,12 @@ Misc
> liftMoney :: (Currency a) => (Decimal -> Decimal -> Decimal) -> Money a -> Money a -> Money a
> liftMoney f a b = money (currency a) (raw a `f` raw b)
-> fromRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
-> fromRate a b m = let c = raw m
-> rate = xrate a
-> in money b $ c *. rate
-
> toRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
> toRate a b m = let c = raw m
-> rate = recip $ xrate b
+> rate = recip $ xrate a
> in money b $ c *. rate
+
+> fromRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
+> fromRate a b m = let c = raw m
+> rate = xrate b
+> in money b $ c *. rate
View
@@ -8,12 +8,12 @@ module Data.Money ( Currency(..)
, HasSign(..)
, Sign(..)
, Position(..)
- , leftSign
- , rightSign
+ , leftSign, rightSign
, currency
, money
- , USD, CAD, EUR
- , usd
+ , fm
+ , USD, CAD, EUR, GenericC
+ , usd, rateOf
) where
```
@@ -260,6 +260,11 @@ precision = 6
```
```haskell
+rateOf :: Double -> GenericC
+rateOf = GenericC
+```
+
+```haskell
fm :: RealFrac f => f -> Decimal
fm = realFracToDecimal precision
```
@@ -327,15 +332,15 @@ liftMoney f a b = money (currency a) (raw a `f` raw b)
```
```haskell
-fromRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
-fromRate a b m = let c = raw m
- rate = xrate a
- in money b $ c *. rate
-```
-
-```haskell
toRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
toRate a b m = let c = raw m
- rate = recip $ xrate b
+ rate = recip $ xrate a
in money b $ c *. rate
```
+
+```haskell
+fromRate :: (Currency a, Currency b) => a -> b -> Money a -> Money b
+fromRate a b m = let c = raw m
+ rate = xrate b
+ in money b $ c *. rate
+```

0 comments on commit 3a870b4

Please sign in to comment.