什么是克罗克福德定律?

bro*_*s94 14 monads haskell functional-programming

最近有人提到了关于单子的"克罗克福德定律".谷歌在结果方面表现得很少.有人知道这是什么吗?

Mat*_*ick 31

假设"克罗克福德定律"是他在视频中早期提到的诅咒,他指的是这种常见现象(在这里更加雄辩地描述):

  1. 人X不懂单子
  2. 人X长期努力工作,并且修理monad
  3. 人X经历了惊人的启蒙感,想知道为什么其他人不会同样开悟
  4. person X gives horrible, incomplete, inaccurate, oversimplified, and confusing explanation of monads to others which probably makes them think that monads are stupid, dumb, worthless, overcomplicated, unnecessary, something incorrect, or a mental wank-ercise

Here's are some of the reasons why I think The Curse exists:

  • forgetting how different functional programming is from so-called "mainstream" programming. If you don't already have a good understanding of what FP is, and why people do it, things built using FP won't make sense. Such things take time and effort
  • forgetting how different capturing effects as first-class citizens is from effects provided by the system (exceptions or mutable state, for example): same as above
  • lack of good motivating examples. You know, stuff like "this is the problem, here's the typical solution, but oh wait, the typical solution has these problems so let's see how we can cleanly fix those using monads!" That's a lot more work than the tired old example about null pointer exceptions
  • forgetting what a monad provides -- lots of "monad" examples I see actually work just fine as Functor or Applicative Functor examples
  • forgetting that monads are built within Haskell. Question: if monads suddenly disappeared, would you still be able to do I/O in Haskell?
  • thinking that monads require syntactic support, or a certain type system
  • thinking that monads are only about mutable state or I/O

I have fallen victim to The Curse. :(

It sounds like Crockford has as well, based on one of the questions at the end: "so monads are basically just the Builder pattern?" IMHO, it's a great video for learning kick-ass Javascript techniques, but not so great if you actually want to learn about monads.

If you are trying to learn about monads, just put in the time and effort and do lots of examples. Reimplement all the monad instances and combinators from scratch. Eventually you will be in a position to fall victim to The Curse as well!

  • 我认为问题在于向命令式程序员解释 monad 就像向鱼解释水一样。他们以前所做的一切都根深蒂固,以至于他们认为他们的法律是理所当然的。了解 monad 是什么的最好方法实际上是尝试构建严肃的程序 * 没有 * 它们。 (2认同)