为什么将严格性引入功能称为seq? [英] Why is the strictness-introducing function called seq?

查看:49
本文介绍了为什么将严格性引入功能称为seq?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 seq 函数,以及为什么有必要引入严格性以提高效率.我不明白的是,为什么这个原语称为 seq (与严格性无关)?

I understand the seq function and why it's necessary to introduce strictness for efficiency. What I don't understand is, why is this primitive called seq (and not something to do with strictness)?

推荐答案

TL; DR:Miranda称其为 seq ,它是在(可能)已经存在 sequence 时引入的.一个为Monads设计的东西,而($!)在短时间内被称为 strict .

TL;DR: Miranda called it seq, it was introduced when sequence was (probably) already a thing for Monads, and ($!) was known as strict for a short time.

之所以称为 seq ,是因为它在seq .rel ="noreferrer">米兰达语和以前的语言,至少根据 A保罗·休达克(John Hughes),约翰·休斯(John Hughes),西蒙·佩顿·琼斯(Simon Peyton Jones)和菲利普·瓦德勒(Philip Wadler)撰写的《 Haskell的历史:随班随便》

It is called seq because it was called seq in Miranda and previous languages, at least according to A History of Haskell: Being Lazy With Class by Paul Hudak, John Hughes, Simon Peyton Jones and Philip Wadler.

出于相同的原因,

seq 和数据结构的严格组成部分已经在Miranda中出现(Turner,1985),实际上, seq 已被用于修复空间泄漏.从1980年代初期开始就一直在懒惰程序中学习(Scheevel,1984; Hughes,1983)

Both seq and strict components of data structures were already present in Miranda for the same reasons (Turner, 1985), and indeed seq had been used to fix space leaks in lazy programs since the early 1980s (Scheevel, 1984; Hughes, 1983)

请注意, Turner仅在1985年的论文,而不是 seq 本身,而Scheevel的"NORMA Sasl手册"似乎丢失了,或者至少在Internet上不可用.休斯论文(上述休斯,1983年")也没有引入 seq .

Note that Turner only introduced the strict components in the 1985 paper, not seq itself, and Scheevel's "NORMA Sasl manual" seems to be lost or at least not available on the Internet. Hughes thesis ("Hughes, 1983" above) doesn't introduce seq either.

无论哪种方式, seq 是Mirandas标准环境的一部分,并且还暗示了为什么它被称为 seq :

Either way, seq was part of Mirandas standard environment and also contains a hint why it was called seq:

`seq'应用于两个值,返回第二个值,但检查第一个值是否未完全未定义.有时需要以确保交互式程序中的正确同步.

`seq' applied to two values, returns the second but checks that the first value is not completely undefined. Sometimes needed, e.g. to ensure correct synchronisation in interactive programs.

正确同步或后续继续.

现在,为什么在Haskell中不将其简单地称为 strict ?甚至序列?

Now, why wasn't that simply called strict in Haskell? Or even sequence?

好吧,事实证明 Haskell 1.3 引入了 seq ,也引入了 Monad ,因此, sequence :: Monad m =>[马]->m().因此, sequence 不能作为名称使用.

Well, it turns out that Haskell 1.3, which introduced seq, did also introduce Monad, and thus sequence :: Monad m => [m a] -> m (). Therefore, sequence was not available as a name.

现在 sequence 不在画面中,让我们看一下 strict . strict 包含在1.3中,因为1.3 引入了 Eval typeclass :

Now that sequence was out of the picture, let's have a look at strict. strict was included in 1.3, since 1.3 introduced an Eval typeclass:

seq :: Eval a => a -> b -> b
strict :: Eval a => (a -> b) -> (a -> b)
strict f = \x -> seq x (f x)

Eval strict 都没有按原样进入Haskell98.相反, Eval 被完全删除,因为它以两种方式都适用于所有类型,并且 strict 重命名为($!).

Neither Eval nor strict didn't make the cut into Haskell98 as-is. Instead, Eval was completely removed, as it applied to all types either way, and strict was renamed to ($!).

这篇关于为什么将严格性引入功能称为seq?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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