What about something like:import Data.IORef ( IORef, newIORef, readIORef, writeIORef )newCounter :: IO (IO Int)newCounter = docounterRef <- newIORef 0 :: IO (IORef Int)let getCount :: IO IntgetCount = docount <- readIORef counterRefwriteIORef counterRef (count + 1)return countreturn getCountThe user calls this function which creates the cache and returns the stateful function. You can use MVars instead of IORefs if you want it to work concurrently.On Sun, Jul 8, 2018 at 2:29 AM Dennis Raddle <dennis.raddle@gmail.com> wrote:______________________________In this one use case, there might be a simpler solution, but I have encountered lots of situations in which a particular algorithm could benefit from an associated stored cache of information. The most natural way to write an algorithm, sometimes, is in terms of its past decisions or past state of the program, interacting with current state.D_________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell- cafe
Only members subscribed via the mailman list are allowed to post.