-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.hs
26 lines (24 loc) · 847 Bytes
/
example.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import Financial.EuroFXRef
import Network.HTTP.Conduit (parseUrl)
import Control.Applicative
import Control.Exception
import Control.Monad
import qualified Data.Map as M
import Data.Time.Format
import Prelude hiding (catch)
import System.Locale (defaultTimeLocale)
main = do
r <- rebase (Currency "USD") <$> fetch
dumpRates r
`catch` (\exc -> do
putStrLn $ "FAILED: "++show (exc :: EuropeanCentralBankException)
return ())
`catch` (\exc -> do
putStrLn $ "IOException: "++show (exc :: IOException)
return ())
dumpRates :: Rates Double -> IO ()
dumpRates r = do
let Currency cur = raReference r
putStrLn $ "The value of "++ cur ++ " 1 in each currency on "++formatTime defaultTimeLocale "%F" (raTime r)
forM_ (M.assocs . raRates $ r) $ \(Currency cur, rate) -> do
putStrLn $ cur ++ " " ++ show rate