
Davi,
Perhaps you could use openTempFile
(http://haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/System-IO.htm...
It will create a file with a unique name and open it for you, you can
then just close it and pass the filename to your program.
Patrick
On Fri, Jul 22, 2011 at 3:10 AM, Davi Santos
Hello all, I have massive (parallel if possible) system calls to an external non-deterministic program. Each time it is executed, it creates a file depending on a command line option 'opt' (input files path, for example). How can I ensure the file name will be unique? maybe with a global counter? My temporary solution have been to use a large random number: ----------- mysteriousExecution :: String -> IO () mysteriousExecution opt = do number <- rand run $ "mysterious-command " ⊕ opt ⊕ " --create-file=" ⊕ number rand = do a ← getStdRandom (randomR (1,999999999999999999999999999999999)) ∷ IO Int let r = take 20 $ randomRs ('a','z') (mkStdGen a) ∷ String return r ======== I'm trying to avoid additional parameters to 'mysteriousExecution'. I tried a counter also (to replace rand), but I don't know how could I start it inside 'mysteriousExecution'. c ∷ IO Counter c = do r ← newIORef 0 -- start return (do modifyIORef r (+1) readIORef r) If somebody says everything is wrong, ok. I understand. 18 years of imperative programming world can damage the brain. Thanks _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- ===================== Patrick LeBoutillier Rosemère, Québec, Canada