我打算怎么使用排序?

发布于 2025-02-04 22:50:03 字数 360 浏览 2 评论 0原文

在Haskell Turtle中,Sort具有类型(函数IO,Monadio io,ord a)=>壳A-> io [a]。它采用外壳单元的形式的流,将其分为列表,然后将其包装在monadio上???

这对我来说似乎是违反直觉的。我的初学者眼睛说monadio仅在与外界互动时才能使用,sort不需要做。

我本来希望sort将为(ord a)=>壳A->壳A,因此非常适合流。

这是软件包作者的监督,还是我不了解应该如何使用sort

In Haskell Turtle, sort has the type (Functor io, MonadIO io, Ord a) => Shell a -> io [a]. It takes a stream in the form of a Shell monad, sorts it into a list, but then wraps it in a MonadIO???

This seems counter-intuitive to me. My beginner eyes say that a MonadIO should only be used when interacting with the outside world, which sort doesn't need to do.

I would have expected sort to be (Ord a) => Shell a -> Shell a so it fits into a stream nicely.

Is this an oversight by the package authors, or am I not understanding how sort should be used?

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

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

发布评论

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

评论(1

和我恋爱吧 2025-02-11 22:50:03

monadio io => io [a]shell a好,因为shellmonadio实例和选择提升列表到shell s。因此,如果愿意,您可以编写自己的更具体的sort具有您喜欢的类型,并使用Turtle提供的sort实现:

sortStream :: Ord a => Shell a -> Shell a
sortStream = sort >=> select

MonadIO io => io [a] is better than Shell a, because Shell is a MonadIO instance and select lifts lists to Shells. So, if you want, you can write your own more specific sort that has the type you like, implemented with the sort provided by turtle:

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