Skip to content

Commit

Permalink
encapsulate unsafe list-accumulators in an abstract module
Browse files Browse the repository at this point in the history
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
gasche committed Feb 4, 2014
1 parent 17d09ff commit 75eab57
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 181 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export DOCROOT
BROWSER_COMMAND ?= x-www-browser
export BROWSER_COMMAND

OCAMLBUILD ?= ocamlbuild
OCAMLBUILD ?= ocamlbuild -use-ocamlfind
OCAMLBUILDFLAGS ?= -no-links

ifeq ($(uname_S),Darwin)
Expand Down Expand Up @@ -193,9 +193,9 @@ test-native: prefilter _build/testsuite/main.native _build/$(QTESTDIR)/all_tests
full-test: $(TEST_TARGET)

test-compat: prefilter src/batteries_compattest.ml
ocamlbuild src/batteries_compattest.byte -no-links
ocamlbuild -use-ocamlfind src/batteries_compattest.byte -no-links

test: test-byte test-compat
test: test-native test-compat

###############################################################################
# BENCHMARK SUITE
Expand Down
Loading

0 comments on commit 75eab57

Please sign in to comment.