Skip to content

Forceable and ForceableM

Андрей Мулик edited this page Sep 21, 2023 · 1 revision

Forceable and ForceableM

Forceable is a class of types whose values can be cast to memory-efficient form using a function.

ForceableM is a class of types whose values can be cast to memory-efficient form using a procedure.

Usage

Many operations can be implemented in two ways: with the creation of a new structure and with the reuse of an existing one. Example: Should the take function create a new array or return a reference to a subarray of an existing one? Or do you need to make two functions?

sdp tries to reuse structures whenever possible and create new ones explicitly, for example, using the force function or the copied procedure. Thus, functions and procedures in sdp implement both behaviors.

Note: force and copied do not replace (!$), seq and deepseq. Their task is not to calculate the structure, but to bring it to an efficient representation in memory. For example, force (filter f xs) will not create a fully evaluated copy of the list filter f xs consisting of elements xs satisfying the condition f. Moreover, for the list force = id, and copied = return, because evaluating a list will result in less memory efficient in most cases.

##API

Function Forceable Added ForceableM Added
Create a copy force 0.3 copied 0.3