[darcs-devel] [patch2163] substantial rewrite of 'darcs test'

Ben Franksen bugs at darcs.net
Wed Apr 21 14:57:08 UTC 2021


Ben Franksen <ben.franksen at online.de> added the comment:

> In the long run I think we may have to re-think the idea of defining
> patch application as a monadic action. With a pure apply method that
> works over a witness typed ApplyState we wouldn't need an indexed monad
> to get the more precise typing we desire. The main question is how to
> make this work without keeping too much of the ApplyState in memory.

To elaborate this point a bit, the basic problem we are trying to solve
with the indexed monad is that the state we manipulate in the ApplyMonad
is implicit. It is difficult to track something in the type system if
that something is not passed around explicitly.

The underlying implementation is in the TreeMonad which cleverly tracks
not only the tree but also some meta information about the size of the
changes; this is tracked for each tree item and also in their sum. This
allows it to regularly dump (flush) parts of the state to disk when a
certain threshold is reached, which has the effect of limiting memory
consumption to a fixed amount.

Now, suppose we augment the ApplyState with (a) a type witness and (b)
the change size tracking information as in the TreeMonad. We could then
re-type apply from

  type ApplyState p :: (* -> *) -> *
  apply :: ApplyMonad (ApplyState p) m => p wX wY -> m ()

to

class Apply p where
  type ApplyState p :: (* -> *) -> * -> *
  apply :: Monad m => p wX wY -> PureApplyState p m wX -> m
(PureApplyState p m wY)

Thus, apply would still be monadic (so it can perform e.g. the
underlying IO) but would take and return the ApplyState explicitly and
with proper witnesses.

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/patch2163>
__________________________________


More information about the darcs-devel mailing list