[darcs-devel] darcs monad

Ganesh Sittampalam ganesh at earth.li
Sun Aug 26 19:39:48 UTC 2012


Hi,

I've been going on for a while about the need to replace the IO monad in
Darcs with something custom. There's some initial discussion of this in
http://bugs.darcs.net/issue1895

I hope to get started on this next, after rebase has been merged. I
think it's best to write the code around a typeclass, albeit that
initially at least there would only be one implementation. In the long
run, this should for example make things easier for clients of darcslib
that are already running in a custom monad.

Roughly speaking my current initial plan is to define a class in
Darcs.Repository.Monad:

class DarcsMonad m where
    darcsIO :: IO a -> m a

Then most darcs code with a return type of IO will be changed to use
DarcsMonad - e.g. Int -> IO Char would become DarcsMonad m => Int -> m Char.

As this monad would live at the Repository level, it wouldn't go down
into the Patch code. Very little of that lives in IO in the first place.

Any actual uses of IO would be lifted with darcsIO. Of course I could
just use MonadIO, but the long-term goal is to actually get rid of
darcsIO and instead abstract all the IO that darcs might want to do into
the class.

Getting this basic skeleton is likely to be the most disruptive. Once
that's done, I would probably focus on moving working directory handling
into the monad to allow customisation - we want clients of libdarcs to
have a thread-safe option using absolute paths.

Of course I haven't actually tried this yet, so it may all work out very
differently. Let me know if you have any comments etc.

Cheers,

Ganesh


More information about the darcs-devel mailing list