once-0.4: memoization for IO actions and functions
Package provides single polymorphic function once, that allows you
to memoize IO actions and functions, evaluating them at most once.
>>>let mkStamp = (putStrLn "stamping" >> writeFile "/tmp/stamp" "") :: IO ()>>>-- onceStamp :: IO ()>>>onceStamp <- once mkStamp>>>-- onceStamp actually evaluates mkStamp it wraps first time.>>>onceStampstamping>>>-- but second time result `()' is memoized, no action is performed.>>>onceStamp>>>-- we can memoize functions too>>>foo <- once $ \x -> print "foo" >> print (x :: Int)>>>-- action will be performed once for every distinct argument>>>foo 10foo 10>>>foo 1010>>>foo 4foo 4
Signatures
Modules
- Control