Added types for buffers (0..5 elements), colors (green, yellow, red) and deques made out of those

This commit is contained in:
Georges Dupéron 2018-08-01 00:41:58 +02:00
parent bac59a6495
commit 2ff9f777cf
2 changed files with 51 additions and 2 deletions

View File

@ -1,14 +1,17 @@
.SECONDEXPANSION:
.PHONY: all
all: deques deques.mli Makefile
all: deques deques.mli doc Makefile
deques: deques.ml Makefile
deques: deques.ml deques.cmi Makefile
ocamlc $< -o $@
deques.mli: deques.ml Makefile
ocamlc -i $< > $@
deques.cmi: deques.mli Makefile
ocamlc $< -o $@
.PHONY: print-tool-versions
print-tool-versions: Makefile
ocamlc -version
@ -33,6 +36,12 @@ jacm-final-crop-%.pdf: $$(shell echo '%.pdf' | sed -e 's/^[-0-9]*-page/jacm-fina
}; \
f $$(echo '$*' | sed -e 's/page[0-9]*$$//' -e 's/-/ /g')
doc: deques.ml Makefile
git clean -dfx doc
mkdir doc
ocamlfind ocamldoc -html -all-params -colorize-code -charset utf-8 $< -d $@
touch doc
.PHONY: clean
clean: Makefile
rm jacm-final-page*.pdf jacm-final-crop-*-page*.pdf

View File

@ -0,0 +1,40 @@
(** An implementation of purely functional deques as described by Kaplan and
Tarjan. *)
(** jacm-final.pdf p.8 (584) §4.1 media 60 380 368 40 *)
module Buffers = struct
type 'a buffer0 = unit
type 'a buffer1 = 'a
type 'a buffer2 = 'a * 'a
type 'a buffer3 = 'a * 'a * 'a
type 'a buffer4 = 'a * 'a * 'a * 'a
type 'a buffer5 = 'a * 'a * 'a * 'a * 'a
end
open Buffers
(** jacm-final.pdf p.9 (585) §4.1 media 60 158 368 24 *)
module Colors = struct
type 'a green = Buffer2 of 'a buffer2 | Buffer3 of 'a buffer3
type 'a yellow = Buffer1 of 'a buffer1 | Buffer4 of 'a buffer4
type 'a red = Buffer0 of 'a buffer0 | Buffer5 of 'a buffer5
end
open Colors
(** jacm-final.pdf p.9 (585) §4.1 media 60 134 368 36 *)
type 'a buffer =
Green of 'a green
| Yellow of 'a yellow
| Red of 'a red
(** jacm-final.pdf p.8 / 584 §4.1 60 408 368 48 *)
type 'a deque = {
prefix: 'a buffer;
child: ('a * 'a) deque option;
suffix: 'a buffer;
}
(* jacm-final.pdf p.8 / 584 §4.1 60 480 368 36 *)
(* let rec child i d =
if i = 0 then d
else child (i - 1) d.child *)