In Monads for natural language semantics, Chung-Chieh Shan shows how monads can be used to give a nicely uniform restatement of the standard accounts of some different kinds of natural language phenomena (interrogatives, focus, intensionality, and quantification). He defines two composition operations, A_M
and A'_M
, that are useful for this purpose.
The first is simply ap
. In the powerset monad ap
is non-deterministic function application, which is useful for handling the semantics of interrogatives; in the reader monad it corresponds to the usual analysis of extensional composition; etc.
This makes sense. The secondary composition operation, however, has a type signature that just looks bizarre to me:
(<?>) :: (Monad m) => m (m a -> b) -> m a -> m b
(Shan calls it A'_M
, but I'll call it <?>
here.) The definition is what you'd expect from the types; it corresponds pretty closely to ap
:
g <?> x = g >>= \h -> return $ h x
I think I can understand how this does what it's supposed to in the context of the paper (handle question-taking verbs for interrogatives, serve as intensional composition, etc.). What it does isn't terribly complicated, but it's a bit odd to see it play such a central role here, since it's not an idiom I've seen in Haskell before.
Nothing useful comes up on Hoogle for either m (m a -> b) -> m a -> m b
or m (a -> b) -> a -> m b
.
Does this look familiar to anyone from other contexts? Have you ever written this function?