Posts

Showing posts with the label haskell

Yesod - when should I use runDB and when should I use getDBRunner?

Yesod - when should I use runDB and when should I use getDBRunner? I got a message when I tested mysql with mysqltuner which says that my mysql connections aren't being closed ... I use a custom function I have created for every database interaction: mysql mysqltuner runPoolDB :: YesodPersistRunner site => YesodDB site b -> HandlerT site IO b runPoolDB action = do ((DBRunner runDB), done) <- getDBRunner result <- runDB action done return result Is it the problem? should I just change it to runPoolDB = runDB ? runPoolDB = runDB By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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...