An unusual type signature
Posted
by Travis Brown
on Stack Overflow
See other posts from Stack Overflow
or by Travis Brown
Published on 2010-06-03T04:12:48Z
Indexed on
2010/06/03
4:24 UTC
Read the original article
Hit count: 344
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?
© Stack Overflow or respective owner