-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotSoEasyToTestCode.hs
38 lines (28 loc) · 1017 Bytes
/
NotSoEasyToTestCode.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
27
28
29
30
31
32
33
34
35
36
37
{-# language NoMonomorphismRestriction #-}
{-# language TemplateHaskell #-}
module NotSoEasyToTestCode where
import DI
import System.IO
import Data.IORef
import Control.Monad
import Data.Time
injLeaf "putStrLn"
injLeaf "getCurrentTime"
inj
makeTimer putStrLn getCurrentTime = liftIO $ do
prevTime <- newIORef Nothing
return $ liftIO $ do
pTime <- readIORef prevTime
time <- getCurrentTime
writeIORef prevTime $ Just time
case pTime of
Nothing -> putStrLn $ show time
Just a -> putStrLn $ show time ++ ", diff: " ++ (show $ diffUTCTime time a)
-- Consider importing Shelly to make this even more realistic
liftIO = id
-- Dep "makeTimer" [Dep "putStrLn" [], Dep "getCurrentTime" []]
-- a = (makeTimer, putStrLn, getCurrentTime)
-- makeTimer' = let (f, a, b) = a in f a b
-- Dep "makeTimer" [Dep "putStrLn" [], Dep "getCurrentTime" [], Dep "foo" [Dep "bar" []]]
-- a = (makeTimer, putStrLn, getCurrentTime, (foo, bar))
-- makeTimer' = let (f, a, b, (g, d)) = a in f a b (g d)