


## memoize.pkg -- simple memoization.
#
# See comments in src/lib/std/memoize.api# Compiled by:
# src/lib/std/standard.libpackage memoize
: Memoize # Memoize is from src/lib/std/memoize.api{
fun memoize f
=
{ cache = REF (fn _ = raise exception FAIL "memoize::memoize: uninitialized");
#
fun first_time x
=
{ v = f x;
#
fun later_on _ = v;
cache := later_on;
v;
};
cache := first_time;
fn 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-2013,
## released per terms of SMLNJ-COPYRIGHT.


