Monads有什么特别之处? [英] What is so special about Monads?

查看:102
本文介绍了Monads有什么特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

monad是一种数学结构,基本上在(纯)函数式编程中使用,基本上是Haskell.但是,还有许多其他数学结构可用,例如,应用函子,强单子或单半体.有些具有更具体的含义,有些是更通用的.然而,单子更受欢迎.为什么会这样?

我想出的一个解释是,它们是通用性和特异性之间的最佳结合点.这意味着monad可以捕获有关数据的足够假设,以应用我们通常使用的算法,并且我们通常拥有的数据满足monadic定律.

另一种解释可能是Haskell提供了monad的语法(do-notation),而不提供其他结构的语法,这意味着Haskell程序员(以及函数式编程研究人员)被直观地吸引到monad上,而monad则更通用或更具体(有效) )功能也可以正常工作.

我怀疑这个特殊类型的类(Monad)与其他许多类相比所受到的不成比例的大量关注主要是历史上的uke幸.人们经常将IOMonad相关联,尽管两者是独立有用的想法(与状态monad的问题关联.)

A monad is a mathematical structure which is heavily used in (pure) functional programming, basically Haskell. However, there are many other mathematical structures available, like for example applicative functors, strong monads, or monoids. Some have more specific, some are more generic. Yet, monads are much more popular. Why is that?

One explanation I came up with, is that they are a sweet spot between genericity and specificity. This means monads capture enough assumptions about the data to apply the algorithms we typically use and the data we usually have fulfills the monadic laws.

Another explanation could be that Haskell provides syntax for monads (do-notation), but not for other structures, which means Haskell programmers (and thus functional programming researchers) are intuitively drawn towards monads, where a more generic or specific (efficient) function would work as well.

解决方案

I suspect that the disproportionately large attention given to this one particular type class (Monad) over the many others is mainly a historical fluke. People often associate IO with Monad, although the two are independently useful ideas (as are list reversal and bananas). Because IO is magical (having an implementation but no denotation) and Monad is often associated with IO, it's easy to fall into magical thinking about Monad.

(Aside: it's questionable whether IO even is a monad. Do the monad laws hold? What do the laws even mean for IO, i.e., what does equality mean? Note the problematic association with the state monad.)

这篇关于Monads有什么特别之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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