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

问题描述

延续可以说是单子吗?他们是monads的一个子集,或者他们只是实现monads的一种方式吗?



编辑:或者我错了, monads continuations 更抽象。 (所以我真的在这里比较苹果和橘子)

简单地说,由于monad的'绑定'需要一个有效的延续(计算的其余部分的lambda)作为参数,单子就是这种意义上的延续。另一方面,延续传递风格可以使用monadic语法糖以非CPS语言有效地实现,正如下面的一些混合链接所暗示的那样。



从Haskell的所有关于monads的教程:



一个F#延续monad,用于执行'break'和'继续for for-style-loop





以及将延续monad应用于问题的示例F#:




Can continuations be said to be monads? Are they a subset of monads or are they simply a way of implementing monads?

Edit: Or maybe I got it wrong and monads is a more abstract concept than continuations? (So I'm really comparing apples to oranges here)

解决方案

Briefly, since the 'bind' of a monad takes an effective continuation (a lambda of the 'rest of the computation') as an argument, monads are continuations in that sense. On the flip side, continuation-passing style can be effectively implemented in a non-CPS language using monadic syntax sugars, as suggested by a number of misc links below.

From the 'all about monads' tutorial in Haskell:

https://www.haskell.org/haskellwiki/All_About_Monads#The_Continuation_monad

An F# continuation monad, used to implement 'break' and 'continue' for for-style-loops

http://cs.hubfs.net/forums/thread/9311.aspx

And example of applying a continuation monad to a problem in F#:

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!256.entry

这篇关于延续monad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:15