What is the difference between a monad and a closure?

后端 未结 4 1054
别跟我提以往
别跟我提以往 2021-02-08 11:24

i am kinda confused reading the definition between the two. Can they actually intersect in terms of definition? or am i completely lost? Thanks.

4条回答
  •  我在风中等你
    2021-02-08 12:04

    They're quite different, although monads will often use closures to capture logic.

    Personally I would try to get solid on the definition of closures (essentially a piece of logic which also captures its environment, i.e. local variables etc) before worrying about monads. They can come later :)

    There are various questions about closures on Stack Overflow - the best one to help you will depend on what platform you're working on. For instance, there's:

    • What are closures in .NET?
    • Function pointers, closures and lambda

    Personally I'm only just beginning to "grok" monads (thanks to the book I'm helping out on). One day I'll get round to writing an article about them, when I feel I understand them well enough :)

提交回复
热议问题