-- | applies the given function to the state in the mutable state reference given (with `write_prep`), and also returns the second output of the function.
-- strict superset of ::  Participant_State_Var -> (Participant_State -> (Participant_State, a)) -> IO a
modify_and_read :: (Hetcons_State a) => (MVar a) -> (a -> (IO (a, b))) -> IO b
modify_and_read s f = modifyMVar s (\v -> do { (v', r) <- f v
                                             ; return (write_prep v', r)})
modify_and_read :: (Hetcons_State a) => (MVar a) -> (a -> (IO (a, b))) -> IO b
modify_and_read s f = modifyMVar s (\v -> do { (v', r) <- f v
                                             ; return (write_prep v', r)})
modify_and_read s f = modifyMVar s (\v -> do { (v', r) <- f v
                                             ; return (write_prep v', r)})