Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

lazy(3o) [debian man page]

Lazy(3o)							   OCaml library							  Lazy(3o)

NAME
Lazy - Deferred computations. Module Module Lazy Documentation Module Lazy : sig end Deferred computations. type 'a t = 'a lazy_t A value of type 'a Lazy.t is a deferred computation, called a suspension, that has a result of type 'a . The special expression syntax lazy (expr) makes a suspension of the computation of expr , without computing expr itself yet. "Forcing" the suspension will then compute expr and return its result. Note: lazy_t is the built-in type constructor used by the compiler for the lazy keyword. You should not use it directly. Always use Lazy.t instead. Note: Lazy.force is not thread-safe. If you use this module in a multi-threaded program, you will need to add some locks. Note: if the program is compiled with the -rectypes option, ill-founded recursive definitions of the form let rec x = lazy x or let rec x = lazy(lazy(...(lazy x))) are accepted by the type-checker and lead, when forced, to ill-formed values that trigger infinite loops in the garbage collector and other parts of the run-time system. Without the -rectypes option, such ill-founded recursive definitions are rejected by the type-checker. exception Undefined val force : 'a t -> 'a === force x forces the suspension x and returns its result. If x has already been forced, Lazy.force x returns the same value again with- out recomputing it. If it raised an exception, the same exception is raised again. Raise Undefined if the forcing of x tries to force x itself recursively. === val force_val : 'a t -> 'a force_val x forces the suspension x and returns its result. If x has already been forced, force_val x returns the same value again without recomputing it. Raise Undefined if the forcing of x tries to force x itself recursively. If the computation of x raises an exception, it is unspecified whether force_val x raises the same exception or Undefined . val lazy_from_fun : (unit -> 'a) -> 'a t lazy_from_fun f is the same as lazy (f ()) but slightly more efficient. val lazy_from_val : 'a -> 'a t lazy_from_val v returns an already-forced suspension of v This is for special purposes only and should not be confused with lazy (v) . val lazy_is_val : 'a t -> bool lazy_is_val x returns true if x has already been forced and did not raise an exception. OCamldoc 2012-06-26 Lazy(3o)

Check Out this Related Man Page

Scalar::Defer(3pm)					User Contributed Perl Documentation					Scalar::Defer(3pm)

NAME
Scalar::Defer - Lazy evaluation in Perl SYNOPSIS
use Scalar::Defer; # exports 'defer', 'lazy' and 'force' my ($x, $y); my $dv = defer { ++$x }; # a deferred value (not memoized) my $lv = lazy { ++$y }; # a lazy value (memoized) print "$dv $dv $dv"; # 1 2 3 print "$lv $lv $lv"; # 1 1 1 my $forced = force $dv; # force a normal value out of $dv print "$forced $forced $forced"; # 4 4 4 DESCRIPTION
This module exports two functions, "defer" and "lazy", for constructing values that are evaluated on demand. It also exports a "force" function to force evaluation of a deferred value. defer {...} Takes a block or a code reference, and returns a deferred value. Each time that value is demanded, the block is evaluated again to yield a fresh result. lazy {...} Like "defer", except the value is computed at most once. Subsequent evaluation will simply use the cached result. force $value Force evaluation of a deferred value to return a normal value. If $value was already a normal value, then "force" simply returns it. is_deferred $value Tells whether the argument is a deferred value or not. (Lazy values are deferred too.) The "is_deferred" function is not exported by default; to import it, name it explicitly in the import list. NOTES
Deferred values are not considered objects ("ref" on them returns 0), although you can still call methods on them, in which case the invocant is always the forced value. Unlike the "tie"-based Data::Lazy, this module operates on values, not variables. Therefore, assigning another value into $dv and $lv above will simply replace the value, instead of triggering a "STORE" method call. Similarily, assigning $dv or $dv into another variable will not trigger a "FETCH" method, but simply propagates the deferred value over without evaluationg. This makes it much faster than a "tie"-based implementation -- even under the worst case scenario, where it's always immediately forced after creation, this module is still twice as fast than Data::Lazy. CAVEATS
Bad things may happen if this module interacts with any other code which fiddles with package 0. Performance of creating new deferred or lazy values can be quite poor under perl 5.8.9. This is due a bugfix since 5.8.8, where re- blessing an overloaded object caused bad interactions with other references to the same value. 5.8.9's solution involves walking the arenas to find all other references to the same object, which can cause "bless" (and thus "defer" in Scalar::Defer to be up to three orders of magnitude slower than usual. perl 5.10.0 and higher do not suffer from this problem. SEE ALSO
Data::Thunk, which implements "lazy" values that can replace itself upon forcing, leaving a minimal trace of the thunk, with some sneaky XS magic in Data::Swap. AUTHORS
Audrey Tang <cpan@audreyt.org> COPYRIGHT
Copyright 2006, 2007, 2008, 2009 by Audrey Tang <cpan@audreyt.org>. This software is released under the MIT license cited below. The "MIT" License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. perl v5.10.1 2010-02-17 Scalar::Defer(3pm)
Man Page