除了 Option 之外,标准 Scala monad 是什么?

发布于 2025-01-04 21:44:36 字数 79 浏览 2 评论 0原文

有时,Option monad 在 Scala 中几乎变成了一种工具。 Scala 标准库中还有其他 monad 吗?

Option monad turns pretty much a facility some times in Scala. Are there any other monads in Scala standard library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吝吻 2025-01-11 21:44:36

路易吉的答案是正确的,但恕我直言,信息量不大。

所有集合都可以实现 monad 接口,但其中 flatMap 的签名不是 monad 的 flatMap。不过,大多数时候它们的行为就像单子一样。 Luigi 列出的几乎所有类都与集合相关。

LeftProjectRightProject 指的是 Either。基本上,Either 不是一个 monad,但是如果你“投影”其中一侧,那么该一侧的行为非常像一个 Option monad。

Parser 是一个 monad,它构成了解析器组合器的基础。

我承认我不认识ControlContext。我想知道它是否与延续(也是单子)有关。

Luigi's answer is correct, but not very informative, IMHO.

All collections can implement the monad interface, but the signature for flatMap in them is not a monad's flatMap. They'll act like monads most of the time, though. Almost all of the classes listed by Luigi are related to collections.

LeftProject and RightProject refers to Either. Basically, Either is not a monad, but if you "project" one of the sides, then that side acts pretty much like an Option monad.

Parser is a monad, which forms the basis of parser combinators.

I admit I do not recognize ControlContext. I wonder if it is related to continuations (which are monads as well).

猫七 2025-01-11 21:44:36

您可以通过在 API 索引。它给出:

FilterMonadic 
Stream 
StreamWithFilter 
TraversableMethods 
Iterator 
ParIterableLike 
ParIterableLike 
ParIterableViewLike 
TraversableLike 
WithFilter 
MonadOps 
TraversableProxyLike 
TraversableViewLike 
LeftProjection 
RightProjection 
Option 
WithFilter 
Responder 
Zipped 
ControlContext
Parser 

You can work this out by looking up the tell-tale flatMap in the API index. It gives:

FilterMonadic 
Stream 
StreamWithFilter 
TraversableMethods 
Iterator 
ParIterableLike 
ParIterableLike 
ParIterableViewLike 
TraversableLike 
WithFilter 
MonadOps 
TraversableProxyLike 
TraversableViewLike 
LeftProjection 
RightProjection 
Option 
WithFilter 
Responder 
Zipped 
ControlContext
Parser 
秋意浓 2025-01-11 21:44:36

以下是 Scalaz 中三个源文件的链接:

看一下实例声明。这可能会让您了解标准库中的哪些类型满足单子接口。

Here are the links to three sources files from Scalaz:

Take a look at instance declarations. That might give you an idea about what types from the standard library satisfy the monadic interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文