Created
March 31, 2016 15:26
-
-
Save laser/2c6adfd248e327b50e5cad35cb219c62 to your computer and use it in GitHub Desktop.
Dynamic / Dispatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Dispatch where | |
import Data.Dynamic | |
import Control.Monad.Reader.Class | |
-- THINGS WE WANT | |
-- 1. we want to avoid having to duplicate the type of the members of a | |
-- type class in our test (like Fixture) | |
-- 2. we want to be able to record the arguments applied to a test function | |
-- 3. we want to be able to control the return value from a test function | |
-- 4. we want to be able to control #2 and #3 from inside the "it-block" | |
type Testy = ReaderT Dispatch IO | |
type Dispatch = (Typeable a) => String -> a | |
instance Timeful Testy where | |
currentPOSIXTime = asks ($ "currentPOSIXTime") | |
instance Persistence Testy where | |
insertDeveloper = asks ($ "insertDeveloper") | |
override :: MonadReader Dispatch m => String -> Dynamic -> m a -> m a | |
override name f act = local alter act | |
where | |
alter dict method = if method == name then fromDyn (error "woops wrong type") f else dict method | |
t :: Testy a -> Testy a | |
t = id | |
f :: Something -> Testy a | |
let f _ = t $ error "omgbbq" | |
override "insertDeveloper" f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment