Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. 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?
- Loading branch information