Skip to content

Commit 4986511

Browse files
OCaml version of CTFP (#201)
* OCaml version of the book upto chapter 24 * Checking in Chapter 25 * Adding Ch 26 * Add final two chapters * Add Marcello Seri's comments * Ch 25 changes * Ch 26 * Run formatter * Adding OCaml tweaks in the half-title + colophon * Adding links in the colophon Co-authored-by: Igal Tabachnik <hmemcpy@gmail.com>
1 parent e72ef6b commit 4986511

File tree

483 files changed

+2119
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+2119
-7
lines changed

src/Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Igal Tabachnik, 2007.
22
# Based on work by Andres Raba et al., 2013-2015.
33

4-
.PHONY: default all clean out-dir version.tex
4+
.PHONY: default all clean out-dir version.tex scala ocaml
55

66
DIR := $(shell pwd)
77
GIT_VER := $(shell git describe --tags --always --long | tr -d '\n')
@@ -13,16 +13,21 @@ DEFAULTTOPTEX = ctfp-reader.tex ctfp-print.tex
1313

1414
SCALATEXFILES = ctfp-reader-scala.tex ctfp-print-scala.tex # todo make this a macro
1515

16+
OCAMLTEXFILES = ctfp-reader-ocaml.tex ctfp-print-ocaml.tex # todo make this a macro
17+
1618
# Top-level LaTeX files from which CTFP book can be generated
17-
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES)
19+
TOPTEXFILES = version.tex $(DEFAULTTOPTEX) $(SCALATEXFILES) $(OCAMLTEXFILES)
1820

1921
# Default PDF file to make
2022
DEFAULTPDF:=$(DEFAULTTOPTEX:.tex=.pdf)
2123

2224
# Scala PDF file to make
2325
SCALAPDF:=$(SCALATEXFILES:.tex=.pdf)
2426

25-
# Other PDF files for the CTFP book
27+
# OCaml PDF file to make
28+
OCAMLPDF:=$(OCAMLTEXFILES:.tex=.pdf)
29+
30+
# Other PDF files for the CTFP book
2631
TOPPDFFILES:=$(TOPTEXFILES:.tex=.pdf)
2732

2833
# Configuration files
@@ -31,21 +36,24 @@ OPTFILES = opt-print-ustrade.tex \
3136
opt-scala.tex
3237

3338
# All the LaTeX files for the CTFP book in order of dependency
34-
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OPTFILES)
39+
TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OCAMLTEXFILES) $(OPTFILES)
3540

3641
default: suffix=''
3742
default: out-dir $(DEFAULTPDF) # todo cover
3843

39-
all: default scala
44+
all: default scala ocaml
4045

4146
scala: suffix='-scala'
4247
scala: out-dir version.tex $(SCALAPDF)
4348

49+
ocaml: suffix='-ocaml'
50+
ocaml: out-dir version.tex $(OCAMLPDF)
51+
4452
# Main targets
4553
$(TOPPDFFILES) : %.pdf : %.tex $(TEXFILES)
4654
if which latexmk > /dev/null 2>&1 ;\
4755
then \
48-
latexmk -shell-escape -interaction=nonstopmode -halt-on-error -norc -jobname=ctfp -pdflatex="xelatex %O %S" -pdf $< ;\
56+
latexmk -shell-escape -interaction=nonstopmode -halt-on-error -norc -jobname=ctfp -pdflatex="xelatex %O %S" -pdfxe $< ;\
4957
mv ctfp.pdf ../out/$(GIT_VER)/$(subst ctfp,$(OUTPUT),$(subst ctfp-reader,$(OUTPUT),$*)).pdf ;\
5058
else @printf "Error: unable to find latexmk. Is it installed?\n" ;\
5159
fi
@@ -64,5 +72,5 @@ clean:
6472
if which latexmk > /dev/null 2>&1 ; then latexmk -CA; fi
6573
rm -rf ../out
6674

67-
clean-minted:
75+
clean-minted:
6876
rm -rf _minted-*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module type Polymorphic_Function_F = sig
2+
type a
3+
type b
4+
5+
val f : a -> b
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module type Polymorphic_Function_G = sig
2+
type b
3+
type c
4+
5+
val g : b -> c
6+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Compose_Example
2+
(F : Polymorphic_Function_F)
3+
(G : Polymorphic_Function_G with type b = F.b) =
4+
struct
5+
(** OCaml doesn't have a compose operator. So, creating one. **)
6+
let ( >> ) g f x = g (f x)
7+
8+
let compose : 'a -> 'c = G.g >> F.f
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Compose_Three_GF = functor(F:Polymorphic_Function_F)(G:Polymorphic_Function_G with type b = F.b)(H:Polymorphic_Function_H with type c = G.c) -> struct
2+
let compose : 'a -> 'd = H.h >> (G.g >> F.f)
3+
end
4+
5+
module Compose_Three_HG = functor(F:Polymorphic_Function_F)(G:Polymorphic_Function_G with type b = F.b)(H:Polymorphic_Function_H with type c = G.c) -> struct
6+
let compose : 'a -> 'd = (H.h >> G.g) >> F.f
7+
end
8+
9+
Compose_Three_GF.compose = Compose_Three_HG.compose
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let id x = x
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
f >> id
2+
id >> f
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val alpha : 'a . 'a f -> 'a g
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val alpha : 'a f -> 'a g
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val alpha : 'a f -> 'a g

0 commit comments

Comments
 (0)