Inside a ReaderT StateT IO do block I am trying to call a function inside a Maybe with a Maybe parameter using <*>
but that results in a type error.
onMessage <*> (message update)
If I wrap the expression using return $ onMessage <*> (message update)
it type checks but then the function does not appear to be evaluated.
If I unwrap both the function and the argument and check for Nothing
manually the function is called but that seems ugly.
Is there another operator to use in this context? These are my first Monad Transformer steps and the types are too perplexing to even try and hoogle an answer.
...
type Bot a = ReaderT (BotConfig a) (StateT (BotState a) IO)
...
processUpdate :: Update -> Bot a ()
processUpdate update = do
BotConfig {tw_handlers = MessageHandlers {
tw_onMessage = onMg
}
} <- ask
onMg <*> (message update) -- this is what I would like to do
-- onMg :: Maybe (Message -> Bot a ())
-- message :: Update -> Maybe Message