Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the Haskell function `seq` get its name from?

Tags:

haskell

I get that seq is used to improve performance by avoiding unneeded laziness. I just want to know where the name is derived from? Is it from "sequence" or "sequential"? And how does the name relate to strict evaluation?

like image 258
Daniel PP Cabral Avatar asked Jan 24 '20 16:01

Daniel PP Cabral


People also ask

What is SEQ in Haskell?

From HaskellWiki. The seq function is the most basic method of introducing strictness to a Haskell program. seq :: a -> b -> b takes two arguments of any type, and returns the second. However, it also has the important property that it is magically strict in its first argument.

What is Haskell function?

Advertisements. Functions play a major role in Haskell, as it is a functional programming language. Like other languages, Haskell does have its own functional definition and declaration. Function declaration consists of the function name and its argument list along with its output.

What is the seq function in Haskell?

The seq function is the most basic method of introducing strictness to a Haskell program. seq :: a -> b -> b takes two arguments of any type, and returns the second. However, it also has the important property that it is magically strict in its first argument. In essence, seq is defined by the following two equations: ⊥ `seq` b = ⊥ a `seq` b = b.

What is a function in Haskell?

Haskell - Functions. Functions play a major role in Haskell, as it is a functional programming language. Like other languages, Haskell does have its own functional definition and declaration. Function declaration consists of the function name and its argument list along with its output.

What is a seq?

The Seq a type represents a finite sequence of values of type a. Sequences generally behave very much like lists. The class instances for sequences are all based very closely on those for lists. Many functions in this module have the same names as functions in the Prelude or in Data.List. In almost all cases, these functions behave analogously.

What is where clause in Haskell?

It is just a basic practice syntax, in the coming section of the tutorial we will see the internal working and implementation of where clause in the Haskell programing language. How does Where Function work in Haskell? As we already know that where is a keyword or a function that helps to dived the complex calculations into smaller parts.


1 Answers

It comes from sequence point. That's a well-known concept in C, and it's indeed quite similar to the seq operator in Haskell: every computation on the left should be done before any computation on the right.

Of course, Haskell seq is a bit less demanding than that: it merely requests that the thing on the left is evaluated to weak head normal form before the result on the right is evaluated. And it doesn't really guarantee any particular evaluation order at all, only that if the expression on the left is ⊥ then the one on the right must not be evaluated.

See pseq or deepseq for stronger alternatives, which come closer to what C calls sequence points.


Actually, C or C++ sequence points don't guarantee computation order either, only that any side effects are in the right order. But, in C side effects are ubiquitous so apart from low-level optimisations you can usually assume that sequence-point order will be upheld, whereas GHC will in fact quite often throw seqs away if only it knows that the expressions do not diverge.

like image 66
leftaroundabout Avatar answered Sep 21 '22 08:09

leftaroundabout