On Mon, Sep 11, 2006 at 14:17:30 -0700, Jason Dagit wrote:
> Although I hadn't mentioned it yet, I was actually hoping that at some
> point in the distance future we may extend the IO monad to carry
> around some extra details and at that time logStr could be updated to
> read the opts from an environment.

I think extending the IO monad is more or less the right way to go (and
would be better than my unsafe global flags stuff).  It would also be
handy for the stuff Nathaniel Gray was implementing to pass stuff
generated by the commands to the posthooks, and maybe also as a clean
way to return an exit code.

I have a repository where I had started to do this by using a state
transformer and calling the whole thing DarcsIO, but I never got around
to finishing it.  The code looks like this and could probably be vastly
improved:

type DarcsIO = StateT DarcsStatus IO

-- the idea is that one day we might decide to make this fancier
data DarcsStatus = DarcsStatus
       { dsOpts :: [DarcsFlag] }

dliftIO :: IO a -> DarcsIO a
-- this is trivial for now, but perhaps in the future the darcs
-- monad transformer stack will grow
dliftIO = liftIO

withDarcsIO :: (DarcsStatus -> IO b) -> DarcsIO b
withDarcsIO job = do d <- get
                     dliftIO (job d)

> That's a terrible way to explain it if you're already familiar with
> the Reader monad...so let me try this....I'm thinking we could
> eventually use ReaderT DarcsEnv IO, where DarcsEnv is non-mutable
> information that darcs uses (like configuration options and command
> line flags).  This way we could more transparently access run-time
> options instead of manually passing the data around as we do now.  I
> have yet to try this technique so I don't know how well it works but
> the more experienced haskell programmers in #haskell say it's a great
> way to pass around 'application state'.

Is the reader monad like a state monad without a 'put'?

-- 
Eric Kow                     http://www.loria.fr/~kow
PGP Key ID: 08AC04F9         Merci de corriger mon français.

Attachment: pgpTBRYyMSyxO.pgp
Description: PGP signature

_______________________________________________
darcs-devel mailing list
[email protected]
http://www.abridgegame.org/cgi-bin/mailman/listinfo/darcs-devel

Reply via email to