strictness analysis
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, strictness analysis refers to any algorithm used to prove that a function in a non-strict
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declar ...
language is strict in one or more of its arguments. This information is useful to
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
s because strict functions can be compiled more efficiently. Thus, if a function is proven to be strict (using strictness analysis) at compile time, it can be compiled to use a more efficient
calling convention In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines or functions receive parameters from their caller and how they return a result. When some code calls a function, design choices have been ...
without changing the meaning of the enclosing program. Note that a function f is said to ''diverge'' if it returns \: operationally, that would mean that f either causes abnormal termination of the enclosing program (e.g., failure with an error message) or that it loops infinitely. The notion of "divergence" is significant because a strict function is one that always diverges when given an argument that diverges, whereas a lazy (or non-strict) function is one that may or may not diverge when given such an argument. Strictness analysis attempts to determine the "divergence properties" of functions, which thus identifies some functions that are strict.


Approaches to strictness analysis


Forward abstract interpretation

Strictness analysis can be characterized as a forward
abstract interpretation In computer science, abstract interpretation is a theory of sound approximation of the semantics of computer programs, based on monotonic functions over ordered sets, especially lattices. It can be viewed as a partial execution of a computer prog ...
which approximates each function in the program by a function that maps divergence properties of the arguments onto divergence properties of the results. In the classical approach pioneered by
Alan Mycroft Alan Mycroft is a professor at the Computer Laboratory, University of Cambridge and a Fellow of Robinson College, Cambridge, where he is also director of studies for computer science. Education Mycroft read mathematics at Cambridge then moved t ...
, the abstract interpretation used a two-point
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined **Domain of definition of a partial function **Natural domain of a partial function **Domain of holomorphy of a function * Do ...
with 0 denoting the set \ considered as a subset of the argument or return type, and 1 denoting all values in the type.


Demand analysis

The
Glasgow Haskell Compiler The Glasgow Haskell Compiler (GHC) is an open-source native code compiler for the functional programming language Haskell. It provides a cross-platform environment for the writing and testing of Haskell code and it supports numerous extensions, ...
(GHC) uses a backward abstract interpretation known as demand analysis to perform strictness analysis as well as other program analyses. In demand analysis, each function is modelled by a function from value demands on the result to value demands on the arguments. A function is strict in an argument if a demand for its result leads to a demand for that argument.


Projection-based strictness analysis

Projection-based strictness analysis, introduced by
Philip Wadler Philip Lee Wadler (born April 8, 1956) is an American computer scientist known for his contributions to programming language design and type theory. He is the chair of Theoretical Computer Science at the Laboratory for Foundations of Computer S ...
and R.J.M. Hughes, uses strictness
projection Projection, projections or projective may refer to: Physics * Projection (physics), the action/process of light, heat, or sound reflecting from a surface to another in a different direction * The display of images by a projector Optics, graphic ...
s to model more subtle forms of strictness, such as head-strictness in a list argument. (By contrast, GHC's demand analysis can only model strictness within product types, i.e., datatypes that only have a single constructor.) A function f is considered head-strict if f = f \circ \pi, where \pi is the projection that head-evaluates its list argument.{{cite conference , first = P. , last = Wadler , author2=R.J.M. Hughes , title = Projections for strictness analysis , book-title = Functional programming and computer architecture; LNCS 274 , publisher = Springer-Verlag , date = 1987 There was a large body of research on strictness analysis in the 1980s.


References

Implementation of functional programming languages Static program analysis