更多“单一应用程序”? [英] Something more to "monadic application"?
问题描述
apm :: Monad m =>是否有一个聪明的名字或更深的含义给这个combinator? m(a - > m b) - > m a - > mb
apm fg = f>> =(=
感觉很像(<*>)
的monadic形式,并且在使用带效果的lambda微积分时经常出现。
<解决方案
apm :: Monad m =>是否有一个聪明的名字或更深的含义给这个combinator? m(a - > m b) - > m a - > mb
apm fg = f>> =(=
感觉很像(<*>)
的monadic形式,并且在使用带效果的lambda微积分时经常出现。
其中最近回答。
如果 app
是monadic,则其类型会被转译为
app':: Monad m => m(a - > m b,a) - >但是它也是monadic编程的一部分,它使用函数来引入更大的灵活性(的确,灵活性省略从箭头
是为什么应用程序
是需要的)。因此,这种类型的更好但较不直接的翻译将是:
appm :: Monad m => m(a - > m b) - > m a - > m b
这是您输入的类型。结论:这是一元相当于 app
,它允许您生成一个单项术语并使用它。它可以非常高兴地用一组最小的函数替换>> =
或 join
来定义monad。 / p>
Is there a clever name or deeper meaning to this combinator?
apm :: Monad m => m (a -> m b) -> m a -> m b
apm f g = f >>= (=<< g)
It feels much like the monadic form of (<*>)
and comes up frequently when working with lambda calculus with effects.
解决方案 It's pretty much the monadic equivalent of Arrow's
app :: ArrowApply (~>) => (b ~> c, b) ~> c
which I was answering about recently.
If app
were monadic, its type would be transliterated as
app' :: Monad m => m (a -> m b, a) -> m b
but it's also part of monadic programming to use functions to introduce greater flexibility (indeed, that flexibility omission from Arrow
is why app
is needed). Thus a better, but less literal translation of the type would be
appm :: Monad m => m (a -> m b) -> m a -> m b
which is the type you gave. Conclusion: this is the monadic equivalent of app
, and it allows you to produce a monadic term and use it. It could quite happily replace >>=
or join
in a minimal set of functions to define a monad.
这篇关于更多“单一应用程序”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!