Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we formally say that a function is non-strict in an argument?

Tags:

haskell

We say that a function is strict in its argument if

f ⊥ = ⊥

but how do we say that a function is non-strict in its argument? Can we say that a function is non-strict if

f ⊥ ≠ ⊥

?

How does that extend to functions of many arguments, where we might or might not evaluate an argument depending on the value of some other argument?

I'm asking this in the context of better documenting the strictness properties of Haskell functions using Haddock documentation.

like image 347
tibbe Avatar asked Jan 07 '15 15:01

tibbe


People also ask

What is non strict function?

Operationally, a strict function is one that always evaluates its argument; a non-strict function is one that might not evaluate some of its arguments. Functions having more than one parameter can be strict or non-strict in each parameter independently, as well as jointly strict in several parameters simultaneously.

What does strict mean in programming?

A strict programming language is a programming language which employs a strict programming paradigm, allowing only strict functions (functions whose parameters must be evaluated completely before they may be called) to be defined by the user.

What is a strict function in Haskell?

No, it's not a function whose arguments are evaluated before the call. A strict function is, informally, a function which evaluates its arguments.

What is strict evaluation in Haskell?

Strict evaluation, or eager evaluation, is an evaluation strategy where expressions are evaluated as soon as they are bound to a variable. For example, with strict evaluation, when x = 3 * 7 is read, 3 * 7 is immediately computed and 21 is bound to x.


1 Answers

There's no standard notation for expressing complex strictness properties. It's also no not as simple as just being strict, since for data structures you may need to say exactly how much gets evaluated.

That said, for a simple function like

cond c t e = if c then t else e

you can imagine saying that the strictness is 1 & (2 | 3), meaning that it will evaluate the first argument, and either the second or the third. These are the kind of strictness properties that a simple strictness analyzer will come up with. (And simple ones seem to be the only ones that are worth while.)

like image 147
augustss Avatar answered Oct 12 '22 20:10

augustss