为什么将严格性引入功能称为seq? [英] Why is the strictness-introducing function called 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
,是因为它在
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 indeedseq
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屋!