Difference between revisions of "Reification (programming)"

From Conservapedia
Jump to navigation Jump to search
(Replaced content with 'Is Conservapedia real? Are Conservatives really this stupid?')
m (Reverted edits by ConservapediaISaJOKE (Talk) to last version by Latson19)
 
Line 1: Line 1:
Is Conservapedia real? Are Conservatives really this stupid?
+
'''Reification''' is a concept in [[functional programming]] specifically concerned with the implementation of [[lazy evaluation]] by the [[suspension]] of a [[computation]] in a [[lambda]].
 +
 
 +
Suppose we wish to compute the value of "x+y" in a [[lazy]] functional programming language such as [[Haskell]] or [[Nero]]. This is done with the functional expression <code>(+ x y)</code>. However, if the value of <code>y</code> is <code>nil</code> or perhaps unknown in the current [[context]], this expression will [[segmentation fault|segfault]]. Furthermore, the operation <code>+</code> may be expensive, for example if it represents [[string]] concatenation. Therefore, it is useful to wrap the computation in a [[lambda]], like so: <code>(if (nor (isNil x) (isNil y)) (+ x y) else (yield))</code>. This "wrapping" process is referred to in the [[literature]] as "ification", since a lambda is fundamentally equivalent to an <code>if</code> in functional languages.
 +
 
 +
Ification (a special case of [[lambda lifting]]) prevents the premature evaluation of the wrapped computation. However, it doesn't do anything to ensure lazy computation &mdash; that is, the computation might be evaluated safely but unnecessarily. Therefore, a second lambda is placed around the computation, this time to ensure that the computation is never performed ''until'' and ''unless'' it absolutely needs to be. This second lambda-lifting step is performed quietly behind the scenes in lazy languages such as Nero, but conceptually it looks like this: <code>(if (result_requested) if (nor (isNil x) (isNil y)) (+ x y) else2 (yield))</code>. This second step is referred to as "reification", and it is where lazy languages like Haskell derive most of their power.
 +
 
 +
[[Category:Computer Programming]]

Latest revision as of 04:41, June 7, 2009

Reification is a concept in functional programming specifically concerned with the implementation of lazy evaluation by the suspension of a computation in a lambda.

Suppose we wish to compute the value of "x+y" in a lazy functional programming language such as Haskell or Nero. This is done with the functional expression (+ x y). However, if the value of y is nil or perhaps unknown in the current context, this expression will segfault. Furthermore, the operation + may be expensive, for example if it represents string concatenation. Therefore, it is useful to wrap the computation in a lambda, like so: (if (nor (isNil x) (isNil y)) (+ x y) else (yield)). This "wrapping" process is referred to in the literature as "ification", since a lambda is fundamentally equivalent to an if in functional languages.

Ification (a special case of lambda lifting) prevents the premature evaluation of the wrapped computation. However, it doesn't do anything to ensure lazy computation — that is, the computation might be evaluated safely but unnecessarily. Therefore, a second lambda is placed around the computation, this time to ensure that the computation is never performed until and unless it absolutely needs to be. This second lambda-lifting step is performed quietly behind the scenes in lazy languages such as Nero, but conceptually it looks like this: (if (result_requested) if (nor (isNil x) (isNil y)) (+ x y) else2 (yield)). This second step is referred to as "reification", and it is where lazy languages like Haskell derive most of their power.