为什么引入严格性的函数称为 seq?

Why is the strictness-introducing function called seq?

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

TL;DR:Miranda 称它为 seq,它是在 sequence(可能)已经是 Monads 的时候引入的,而 ($!) 被称为 strict 很短的时间。

米兰达是第一个

它被称为 seq 因为它在 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

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 only introduced the strict components in the 1985 paper,而不是 seq 本身,并且 Scheevel 的 "NORMA Sasl manual" 似乎已丢失或至少无法在 Internet 上找到。 Hughes 论文("Hughes, 1983" 以上)也没有介绍 seq

无论如何,seq was part of Mirandas standard environment 并且还包含一个提示,为什么它被称为 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.

正确同步或sequencing。

其他可能的名称

现在,为什么在 Haskell 中不简单地称为 strict?甚至 sequence?

好吧,原来 Haskell 1.3 引入了 seq,也引入了 Monad,因此也引入了 sequence :: Monad m => [m a] -> m ()。因此,sequence 不能用作名称。

既然 sequence 不在画面中,让我们看看 strictstrict 包含在 1.3 中,因为 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)

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