PreviousUpNext

15.4.1056  src/lib/std/memoize.pkg

## memoize.pkg --  simple memoization.
#
# See comments in    src/lib/std/memoize.api

# Compiled by:
#     src/lib/std/standard.lib

package memoize
:       Memoize                                         # Memoize               is from   src/lib/std/memoize.api
{
    fun memoize f
        =
        {   cache =   REF (\\ _ = raise exception DIE "memoize::memoize: uninitialized");
            #
            fun first_time x
                =
                {   v =  f x;
                    #
                    fun later_on _ =    v;
                
                    cache := later_on;

                    v;
                };
        
            cache := first_time;

            \\ x =   *cache x;
        };
};


## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext