[darcs-devel] darcs patch: allow submitting patches via HTTP POST in addition to ...

John Meacham john at repetae.net
Tue Apr 1 23:00:04 UTC 2008


On Tue, Apr 01, 2008 at 02:54:17PM +0100, Eric Kow wrote:
> >  I actually really dislike how we pass [DarcsFlag] all over the place, as
> >  it's a very un-typed approach.  You can't tell what information you're
> >  passing in, or why, or what effect it will have.
> 
> I wonder if the implicit parameters extension could be useful for
> helping in such a cleanup?
> http://www.cs.chalmers.se/~rjmh/Globals.ps

gawd no. Implicit parameters are a horrible hack, I hope ghc gets rid of
them so people stop getting tempted to use them and code themselves into
a corner. they break beta reduction and complicate type signatures,
their global namespace also makes code that uses them very non-modular.

> And we could avoid making yet another monad.  The extension seems
> simple enough to understand anyway.  At least, I could understand it,
> which is a good sign.

A reader monad is very canonical haskell here.

data Env = Env {
        envFlags :: [DarcsFlags]
        }

newtype DIO a = DIO (ReaderT Env IO a)
        deriving(Monad,Functor,MonadIO, Reader Env)

putInfoLn :: String -> DIO ()
putInfoLn s = do
        flags <- asks envFlags
        unless (Quiet `elem` flags) $ putStrLn s 


things like the http stream cache can also be piped around easily in a
similar fashion.

now you can just use DIO in some places. I find it makes it a _lot_
easier to read and understand code when the incidental environment doesn't get in
the way of the actual input/output parameters. It is hard to tell when a
function is meant to actually do something with the env or just needs it
for putVerbose (which is replicated way to many times)

I don't think things accidentally ending up in DIO will be a problem,
you already require top level type signatures so people can't
unconciously end up with stuff in DIO that wasn't intended. Plus you end
up getting to use all the wonderful monad combinators signifigantly
simplifying code making it easier to grok.

And since the type is abstract, you end up with a lot more safety and A
lot easier to figure out code.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the darcs-devel mailing list