From 2ff9f777cfff7ab41a12c69682382f19dfa2893f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 1 Aug 2018 00:41:58 +0200 Subject: [PATCH] Added types for buffers (0..5 elements), colors (green, yellow, red) and deques made out of those --- Makefile | 13 +++++++++++-- deques.ml | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 50d5d29..e109a98 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/deques.ml b/deques.ml index e69de29..62bb1aa 100644 --- a/deques.ml +++ b/deques.ml @@ -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 *)