ocaml-batteries-team/batteries-included — pull request #529 by gasche (2014-02-03 15:24:25+00:00)
Title: [RFC] a completely encapsulated interface for unsafe batList accumulators

> encapsulate unsafe list-accumulators in an abstract module
>
> This patch is still incomplete, in particular it lacks tests for most
> of the functions changed, but it demonstrates the possibility to
> capture all the accumulator usage under a common abstraction. I think
> the code is provably safe (equivalent to another imperative implementation
> with (type 'a mut_list = 'a list ref) and no Obj.magic at all).
>
> The only function that gave me trouble is 'transpose', as it creates
> an unbounded number of intermediate accumulators. The resulting
> implementation, using continuation-passing to not break
> tail-recursivity, is admittedly much less readable than the previous
> one. Is it a fair cost to pay for safety by encapsulation?

This patch is not proposed for inclusion (it fails the testing requirement) but for discussion in relation to #527.