Memoization for subsequent fold calls
Memoization for subsequent fold calls I'm looking for a technique that allows for memoization between subsequent fold calls against the lists that is being prepended. I looked at memoize library but this doesn't seem to support memoization of higher-order functions, which is the case for folds. I also tried the technique with lazy evaluated map of results but to no avail. Here's simple example code: module Main where import Data.Time printAndMeasureTime :: Show a => a -> IO () printAndMeasureTime a = do startTime <- getCurrentTime print a stopTime <- getCurrentTime putStrLn $ " in " ++ show (diffUTCTime stopTime startTime) main = do let as = replicate 10000000 1 printAndMeasureTime $ foldr (-) 0 as -- just to resolve thunks printAndMeasureTime $ sum as printAndMeasureTime $ sum (1:as) -- recomputed from scratch, could it reuse previous computation result? printAndMeasureTime $ length (as) printAndMeasureTime $ length (1:as) -- recom...