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.
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.
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.
No, it's not a function whose arguments are evaluated before the call. A strict function is, informally, a function which evaluates its arguments.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With