[darcs-devel] darcs patch (Current changes)
David Roundy
droundy at abridgegame.org
Tue Sep 21 03:45:39 PDT 2004
On Mon, Sep 20, 2004 at 07:26:49PM +0200, Juliusz Chroboczek wrote:
> > Perhaps identifyCurrent should be implicit in the various _Current
> > commands? I guess the advantage of the way you wrote it is that you don't
> > need to reidentify it if you do multiple operations...
>
> Yes, that's what I though initially, but it turns out that I'm almost
> always doing a strict identifyCurrent. I guess I could rewrite some
> code in order to reuse the result of identifyCurrent.
>
> There are a couple of places where you actually need the extra
> flexibility provided by the extra argument, that's initialise (which
> needs to create a current from scratch) and repair (which must create
> a current in a format corresponding to a current that has already been
> deleted). So altogether, I think it's easier that way.
>
> Note that when I implement HashedCurrent, the result of
> identifyCurrent will be a non-trivial data structure (it will contain
> all the data from the hash file).
Right. I've wondered (since writing my email) if it might even be
worthwhile to have a withCurrent function, which would be similar to
identifyCurrent, but the "Current" it returns would only be guaranteed
valid until the IO arg fails
withCurrent :: (Current -> IO a) -> IO a
This might be useful for dealing with slurping and temporary directories,
and might also come in handy when "Current" wants to contain an open handle
of some sort to a database, so we could avoid reopening it.
> > A delayed version of withTempDir sounds like a good idea. Or perhaps
> > we could stick a finalizer on the Slurpy that would delete the
> > directory?
>
> That would be the best thing, assuming that ghc finalisers are guaranteed
> to run even if the process terminates before a GC. How do you do
> finalisers in ghc? Could you point me to some docs?
Indeed the GHC finalizers do guarantee to run before program termination,
at least provided the program terminates cleanly (no kill -9, etc).
I believe you can do it using System.Mem.Weak.addFinalizer:
http://haskell.org/ghc/docs/latest/html/libraries/base/System.Mem.Weak.html
> > keepingTemporaryDir :: (FilePath -> IO a) -> IO a
>
> Let's go the whole way:
>
> withDelayedDir :: FilePath -> (FilePath -> (a, IO b)) -> IO b
>
> where the a result is the one the finaliser is stuck on. Then you've
> got
>
> keepingTemporaryDir p f = withDelayedDir p ((\x->(x,x)) . f)
Did you mean perhaps...
withDelayedDir :: FilePath -> (FilePath -> IO (a, b)) -> IO b
?
--
David Roundy
http://www.abridgegame.org
More information about the darcs-devel
mailing list