Why is the strictness-introducing function called seq?

ぐ巨炮叔叔 提交于 2021-02-02 00:30:44

问题


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)?


回答1:


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.

Miranda was first

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.

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)

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.

Either way, seq was part of Mirandas standard environment and also contains a hint why it was called 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.

Correct synchronisation or sequencing.

Other possible names

Now, why wasn't that simply called strict in Haskell? Or even 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.

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)

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 ($!).



来源:https://stackoverflow.com/questions/61479290/why-is-the-strictness-introducing-function-called-seq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!