packages feed

currency-convert 0.1.1.0 → 0.2.1.0

raw patch · 2 files changed

+16/−16 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Currency.Convert: instance GHC.Read.Read (Data.Currency.Convert.Currency s)
- Data.Currency.Convert: instance GHC.Show.Show (Data.Currency.Convert.Currency s)
+ Data.Currency.Convert: instance GHC.Read.Read (Data.Currency.Convert.Currency a)
+ Data.Currency.Convert: instance GHC.TypeLits.KnownSymbol s => GHC.Show.Show (Data.Currency.Convert.Currency s)

Files

Data/Currency/Convert.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE DataKinds, +{-# LANGUAGE DataKinds,+             PolyKinds,              KindSignatures,              ScopedTypeVariables,              RankNTypes,@@ -111,13 +112,13 @@ ) where  import GHC.TypeLits-import Network.HTTP.Simple+import Network.HTTP.Simple hiding (Proxy(..)) import qualified Data.HashMap.Strict as HS import qualified Data.Text as T import Data.Aeson+import Data.Proxy import Control.Applicative import qualified Control.Exception as E-import Debug.Trace  {-|     @'Currency'@ is a wrapper around @Double@ that has a phantom symbol type, @@ -126,17 +127,18 @@     To extract the value from a @'Currency'@ value, use @toRational@ from @Real@. -} data Currency (s :: Symbol) = Currency Double-    deriving (Eq, Ord, Show, Read)+    deriving (Eq, Ord)  -{-|-    @'pprint'@ renders the value the provided currency and its three letter code to a string.+instance KnownSymbol s => Show (Currency s) where+    show (Currency val) = symbolVal (Proxy :: Proxy s) ++ " " ++ show val -    >>> pprint (usd 10)-    10 usd--}-pprint :: forall s. KnownSymbol s => Currency s -> String-pprint (Currency v) = show v ++ " " ++ symbolVal (SProxy :: SProxy s)+instance Read (Currency a) where+    readsPrec _ s = let (currency : value : rest) = words s in+                    let n :: Proxy s +                        n = case someSymbolVal currency of+                                SomeSymbol n' -> n+                    in [((Currency (read value) :: Currency s), unwords rest)]  instance Num (Currency a) where     Currency a + Currency b = Currency $ a + b@@ -156,8 +158,6 @@ instance RealFrac (Currency a) where     properFraction (Currency a) = let (a', b') = properFraction a in (a', Currency b') -data SProxy (s :: Symbol) = SProxy- -- | The Australian Dollar type AUD = Currency "aud" @@ -465,8 +465,8 @@  convert :: forall a b. (KnownSymbol a, KnownSymbol b, ?dict :: [(String, Double)], ?name :: String)             => Currency a -> Currency b-convert (Currency a) = let as = symbolVal (SProxy :: SProxy a) -                           bs = symbolVal (SProxy :: SProxy b) in+convert (Currency a) = let as = symbolVal (Proxy :: Proxy a) +                           bs = symbolVal (Proxy :: Proxy b) in                        case lookup as ?dict of                            Just aRate -> let eurVal = a / aRate in                                case lookup bs ?dict of
currency-convert.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.1.0+version:             0.2.1.0  -- A short (one-line) description of the package. synopsis:            Typesafe currency conversion