jQuery是一个monad [英] Is jQuery a monad

查看:101
本文介绍了jQuery是一个monad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处读过jQuery是monad,并且这个答案显示underscore.js库中的链函数不是monad(但是是comonad)。和回答这个类似的,表明这是monoid。

那么,jQuery是monad吗?

解决方案

不符合单子法。 jQuery 是一个很大的 API ,所以在统计上,它不太可能是意外的一元。因此,我非常怀疑整个 jQuery API可以满足monad规则(即jQuery是monad)。这并不意味着一个给定的(非常有限的)子集可能不满足它们,但是整个API可能包含违反操作的不安全操作因为没有人似乎提供了证据表明API的全部或部分符合法律,所以我建议我们应该假设它的确如此直到提供证据为止。



必须显示:


  • 什么jQuery操作对应于 return (将值提取到jQuery monad中)?

  • jQuery操作对应的是什么绑定,用于将计算粘合在一起?

  • 这些操作的左,右和相关性定律如何保留?



然后,鉴于jQuery API的其他部分,可能违反哪些规则?例如,我可以通过调用其他API函数之一来破坏 bind 吗?



参考资料: cl / 2011/12 / jquery-is-not-a-monad /> jQuery不是monad

  • jQuery仍然不是monad


  • I read somewhere that jQuery is a monad and this answer shows that chain function in underscore.js library is not a monad (but comonad). And answer to this which is similar, shows that is monoid.

    So, is jQuery a monad?

    解决方案

    Most APIs do not satisify the monad laws. jQuery is a large API, so statistically, it is unlikely to be "accidentally" monadic. As a result I am pretty skeptical that the jQuery API as a whole could satisfy the monad laws (i.e. that "jQuery is a monad").

    This doesn't mean that a given (very restricted) subset might not satisfy them, but the API as a whole is likely to contain "unsafe" operations that would violate the laws when used, breaking the abstraction.

    Since no one seems to have offered evidence that the API in whole or part satisifies the laws, I suggest we should assume it does not, until evidence is provided.

    It must be shown:

    • what jQuery operation corresponds to return (lifting a value into the jQuery monad)?
    • what jQuery operation corresponds to bind, for gluing computations together?
    • how do the left-, right- and associativity laws hold over those operations?

    And then, what law violations are possible given the rest of the jQuery API? Can I, for example, break the bind by calling one of the other API functions?

    References:

    这篇关于jQuery是一个monad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆