Here's a constructed monad stack in my program:
type Px a = ReaderT PConf (State PState) a
Where PConf and PState are arbitrary data types holding the configuration and the state of the app.
I need to provide a default implementation so i can test my functions, given a 'PConf' and a 'PState':
p4 :: Px ()
p4 = ???
where
conf = PConf 4 10 10 [0, 1]
state = PState 0 0 $ M.fromList [((x, y), Nothing) | x <- [0..9], y <- [0..9]]
I don't know what to write in "p4 = " so that the implementation uses 'conf' and 'state'. Thanks.
If p4 is a Px () action, then that is not the point you define the conf to pass in, and if state is supposed to be the initial state, not that one either. Instead you should put those in the function that tests p4:
p4 :: Px ()
p4 = ...
test = runState (runReaderT p4 conf) state
where
conf = PConf 4 10 10 [0, 1]
state = PState 0 0 $ M.fromList [((x, y), Nothing) | x <- [0..9], y <- [0..9]]
EDIT: In case your problem is still with writing p4 itself, here's a small mockup p4 that changes some of the state to contain some of the original conf:
p4 = do
PConf x y z _ <- ask
PState m n mp <- get
put $ PState m n (M.insert (x, y) (Just z) mp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With