我应该在Turtle或Foldl包装中使用折痕吗? [英] Should I use folds in Turtle or Foldl packages?

查看:68
本文介绍了我应该在Turtle或Foldl包装中使用折痕吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Turtle时遇到了一些困难,仅在盯着无法理解的错误消息几分钟后,我才意识到我在使用错误的fold函数.

I'm having some difficulty using Turtle and only after several minutes staring at incomprehensible error messages realized that I was using wrong fold function.

https://hackage .haskell.org/package/turtle-1.5.8/docs/Turtle-Shell.html#v:fold https://hackage.haskell. org/package/foldl-1.4.0/docs/src/Control.Foldl.html#fold

为什么会有名称冲突?我不相信这是巧合,但我无法弄清楚.这些固有的折叠类型不同吗?

Why is there a name collision? I don't believe that's coincidence but I cannot figure it out. Are these inherently different kinds of folds?

具体来说,我想使用最长的修改时间将流文件名折叠为单个名称.

To be concrete, I wanted to fold a stream filenames into single name using maximum of modification time.

推荐答案

(首先,我们在此处讨论的折叠不是中的/Data-Foldable.html#v:foldl-39-"rel =" nofollow noreferrer> foldl'函数,它们来自

(First of all, the folds we are talking about here are not the foldr foldl foldl' functions from Data.Foldable, they are from the foldl package, which is conceptually related to the foldl' function from the Data.Foldable, as a sort of versatile generalization, but has separate definitions.)

Fold 数据类型表示要对传入的值序列执行的严格的有状态操作.它的Applicative实例使您可以对相同的值序列运行两个操作. Fold具有很好的属性,它们与值的来源无关.

The Fold datatype repesents a strict, stateful operation to perform on an incoming sequence of values. Its Applicative instance lets you run two operations combined on the same sequence of values. Folds have the nice property that they are agnostic about where the values come from.

每种类型的源将具有其自己的功能来提供值.这些功能可能共享名称fold,但这不是问题,因为通常的建议是导入合格的软件包.

Each type of source will have its own function to feed in the values. These functions might share the name fold, but it isn't a problem because the typical recommendation is to import the packages qualified.

折叠 foldl 包中的>函数可提供任何Foldable容器的内容. 折叠 href ="http://hackage.haskell.org/package/turtle-1.5.8" rel ="nofollow noreferrer"> turtle 会提供Shell的结果.像管道"之类的流媒体库具有自己的适配器.

The fold function from the foldl package feeds the contents of any Foldable container. The fold from turtle feeds the results of a Shell. Streaming libraries like "pipes" have their own adapters.

这篇关于我应该在Turtle或Foldl包装中使用折痕吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆