[darcs-devel] add get_slurp_context, get_slurp_context_maybe, ... [7 patches]

Tomasz Zielonka tomasz.zielonka at gmail.com
Wed Jan 5 13:35:17 PST 2005


On Wed, Jan 05, 2005 at 12:40:47PM -0500, David Roundy wrote:
> Hello,

Hello!

> Sorry about the delay in responding to this.  I was on vacation, and was
> scanning my emails for "darcs patch" in the headers to make sure I
> responded to patches, and thus missed this one.

No problem.

> On Tue, Dec 21, 2004 at 10:08:42PM +0100, Tomasz Zielonka wrote:
> > I am working on removing code duplication in SlurpDirectory. At this point
> > it may result in a slighty worse efficiency. In the long run it should allow
> > us to easily switch to an implementation based on FiniteMaps or something
> > similar.
> > 
> > The first step is introducing get_slurp_context* functions, which allow
> > to split the slurpy into a subtree and the rest (context):
> > 
> > get_slurp_context :: FileName -> Slurpy -> Maybe (Slurpy -> Slurpy, Slurpy)
> > get_slurp_context_maybe :: FileName -> Slurpy -> Maybe (Maybe Slurpy -> Maybe Slurpy, Slurpy)
> > get_slurp_context_list :: FileName -> Slurpy -> Maybe ([Slurpy] -> [Slurpy], Slurpy)
> > 
> > You can modify the subtree for a given path and then apply the context
> > function to it to get the whole tree.
> > 
> > Any thoughts about it?
> > I hope I am not stepping on someone else's toes.
> 
> Hmmm.  It looks nice, although I'd like to see tests as to how much it
> harms efficiency.

OK, I will do some tests on darcs' repository. 

> I'd also much rather see this implemented as a monad.
> See my response to Ian's lazy parsing patch for a discussion of where I'd
> like to see these sorts of things go.
>
> I also find these names a bit confusing.  Could we perhaps get by with
> something like
> 
> newtype SlurpMonad = SM (Slurpy -> Maybe Slurpy)

You probably mean something like this
    newtype SlurpMonad a = SM (Slurpy -> Maybe (Slurpy, a))
or
    newtype SlurpMonad a = SM (Slurpy -> (Maybe Slurpy, a))
or simply
    newtype SlurpMonad a = SM (StateT Slurpy (Error String a))

> modifySlurpy :: Slurpy -> SlurpMonad () -> Maybe Slurpy
> modifySubSlurpy :: FileName -> SlurpMonad () -> SlurpMonad ()

Nice idea, but your modify* functions can be easily implemented with my
get_slurp_context_* functions. I would rather keep them (get_slurp_context_*)
as they seem to be more general, or at least more primitive. Of course they may
become inadequate if you use a different definition of SlurpMonad.

> So far, I haven't really understood the get_slurp_context_list, so I'll want
> to understand that before applying.

Actually, it seems to be unnecessary. It just appeared as a natural
specialisation of get_slurp_context_generic. It allows to replace a single
slurpy with zero, one or more slurpies. The zero and one cases are already
covered by get_slurp_context_maybe, and I don't see any use for the "more"
case. So, we can probably safely remove this function.

Best regards,
Tomasz




More information about the darcs-devel mailing list