[darcs-devel] Context witnesses of the Repository type

Ganesh Sittampalam ganesh at earth.li
Tue Jun 16 20:33:13 UTC 2015


On 16/06/2015 01:03, Ben Franksen wrote:
> I have done a lot of poking into the deep and dark internals lately. One 
> thing that came up is that I started to wonder whether the witnesses of the 
> Repository type are really worth the bother. It appears to me that in most 
> cases they merely add noise to the type signatures and to the code (to get 
> one or more arguments in shape using ugly things like unsafeCoerce*).
> 
> I'd be interested how this is perceived by others. Have the Repository 
> witnesses ever helped you to avoid making a mistake, for instance during 
> some refactoring? If yes, do you think they are valuable enough to justify 
> their cost (in code complexity and readability)?

Personally I like having them. I think they're useful documentation as
well as providing some compiler checking - for me they actually make the
code *more* readable because they give more information about what it's
doing. For example I can see at a glance from the type of a function
that it updates just the tentative state.

I'm not sure if I can point to specific mistakes they've helped me
avoid, but generally having good static types makes me more confident
when refactoring.

I think their biggest weakness is that we don't have a way of enforcing
linearity at present: if you write something to disk, changing the
witnesses, then the compiler doesn't do anything to prevent you re-using
the old repository value with the old witnesses. I'd love to find a way
to fix that.

http://bugs.darcs.net/issue2432 is a good example of this coming up in
practice.

Cheers,

Ganesh


More information about the darcs-devel mailing list