From 09544e1403ba30e51a7220cd049b4ce3988cc17c Mon Sep 17 00:00:00 2001 From: Bryan O'Sullivan Date: Sun, 24 Jun 2007 16:59:43 +0000 Subject: [PATCH] Strictify the fold. --HG-- extra : convert_revision : 879510c3a41039e46f4cd117381470a82861d049 --- System/FilePath/Find.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/System/FilePath/Find.hs b/System/FilePath/Find.hs index e415ac7..44fd935 100644 --- a/System/FilePath/Find.hs +++ b/System/FilePath/Find.hs @@ -249,10 +249,11 @@ find = findWithHandler warnOnError -- | Search a directory recursively, with recursion controlled by a -- 'RecursionPredicate'. Fold over all files found. Any errors that --- occur are dealt with by the given handler. The fold function is --- run from \"left\" to \"right\", so it should be strict in its left --- argument to avoid space leaks. If you need a right-to-left fold, --- use 'foldr' on the result of 'findWithHandler' instead. +-- occur are dealt with by the given handler. The fold is strict, and +-- run from \"left\" to \"right\", so the folded function should be +-- strict in its left argument to avoid space leaks. If you need a +-- right-to-left fold, use 'foldr' on the result of 'findWithHandler' +-- instead. foldWithHandler :: (FilePath -> a -> E.Exception -> IO a) -- ^ error handler -> RecursionPredicate -- ^ control recursion into subdirectories @@ -267,10 +268,12 @@ foldWithHandler errHandler recurse f state path = where visit state path depth st = if F.isDirectory st && evalFI recurse path depth st then traverse state path (succ depth) st - else return (f state (mkFI path depth st)) + else let state' = f state (mkFI path depth st) + in state' `seq` return state' traverse state dir depth dirSt = E.handle (errHandler dir state) $ getDirContents dir >>= - flip foldM (f state (mkFI dir depth dirSt)) (\state name -> + let state' = f state (mkFI dir depth dirSt) + in state' `seq` flip foldM state' (\state name -> E.handle (errHandler dir state) $ let path = dir name in F.getSymbolicLinkStatus path >>= visit state path depth)