[Haskell-beginners] optimisation of code

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Mon Oct 1 16:59:39 UTC 2018


> Hi,

> Current code re-checks file existence always in same order, so worst case is - N files and only last of them does not exists.
> In that case this code will re-check (N-1) files during each consecutive retry.
> This can be optimized by moving already existing files to the end of file list(or dropping them from list completely, if files are only > > added but never removed).
> For this you could re-write `allFilesThere` something like:
> allFilesThere fs = liftIO $ do
>  existing, non_existing <- partitionM (doesFileExist . fromAbsFile) fs
<  return (non_existing++ existing, null non_existing)

> Then allFilesThere could start next iteration by checking previously non-existing files and probably failing much faster.

thanks a lot,  files are never removed, so I can forget already checked files :)


More information about the Beginners mailing list