├── .gitignore
├── .nojekyll
├── Makefile
├── README.md
├── common
├── cheat-style.sty
├── fig
│ ├── ocamlpro_carre_bleu.pdf
│ └── ocamlpro_carre_noir.pdf
└── ocaml-cs.cls
├── docs
├── index.html
├── ocaml-c-api.pdf
├── ocaml-lang.pdf
├── ocaml-libs.pdf
├── ocaml-opam-bw.pdf
├── ocaml-opam.pdf
├── ocaml-stdlib.pdf
├── ocaml-tools.pdf
└── tuareg-mode.pdf
├── licence
└── by-sa.pdf
├── ocaml-c-api
├── Makefile
└── ocaml-c-api.tex
├── ocaml-lang
├── Makefile
└── ocaml-lang.tex
├── ocaml-libs
├── Makefile
└── ocaml-libs.tex
├── ocaml-opam
├── Makefile
├── ocaml-opam-bw.pdf
└── ocaml-opam.tex
├── ocaml-stdlib
├── Makefile
└── ocaml-stdlib.tex
├── ocaml-tools
├── Makefile
└── ocaml-tools.tex
└── tuareg-mode
├── Makefile
├── ocamlmode.tex
└── tuareg-mode.tex
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.aux
3 | *.log
4 | ocaml-c-api/ocaml-c-api.pdf
5 | ocaml-lang/ocaml-lang.pdf
6 | ocaml-lang/ocaml-lang-verb.pdf
7 | ocaml-opam/ocaml-opam.pdf
8 | ocaml-opam/ocaml-tools.pdf
9 | ocaml-stdlib/ocaml-stdlib.pdf
10 | ocaml-libs/ocaml-libs.pdf
11 | ocaml-tools/ocaml-tools.pdf
12 | tuareg-mode/tuareg-mode.pdf
13 | *.out
14 | *.pfg
15 |
--------------------------------------------------------------------------------
/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/.nojekyll
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | $(MAKE) -C ocaml-lang
3 | $(MAKE) -C ocaml-tools
4 | $(MAKE) -C ocaml-stdlib
5 | $(MAKE) -C ocaml-libs
6 | $(MAKE) -C tuareg-mode
7 | $(MAKE) -C ocaml-c-api
8 | $(MAKE) -C ocaml-opam
9 |
10 | DIRS= ocaml-lang ocaml-tools ocaml-stdlib ocaml-libs tuareg-mode \
11 | ocaml-c-api ocaml-opam
12 |
13 | pages:
14 | for dir in $(DIRS); do cp -f $$dir/$$dir.pdf docs/; done
15 | cp -f ocaml-opam/ocaml-opam-bw.pdf docs/
16 |
17 | clean:
18 | $(MAKE) clean -C ocaml-lang
19 | $(MAKE) clean -C ocaml-tools
20 | $(MAKE) clean -C ocaml-stdlib
21 | $(MAKE) clean -C ocaml-libs
22 | $(MAKE) clean -C tuareg-mode
23 | $(MAKE) clean -C ocaml-c-api
24 | $(MAKE) clean -C ocaml-opam
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OCaml Cheat Sheets
2 |
3 | Here: https://ocamlpro.github.io/ocaml-cheat-sheets
4 |
5 | ## Already Released
6 |
7 | * ocaml-opam : The OPAM package manager ( [Black&White PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/ocaml-opam-bw.pdf), [Color PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/ocaml-opam.pdf) )
8 | * ocaml-lang : The OCaml language ( [PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/ocaml-lang.pdf) )
9 | * ocaml-stdlib : The OCaml standard library in the official OCaml distribution ( [PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/ocaml-stdlib.pdf) )
10 | * ocaml-tools : The OCaml standard tools in the official OCaml distribution ( [PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/ocaml-tools.pdf) )
11 | * tuareg-mode : The Tuareg Emacs mode for OCaml ( [PDF](https://ocamlpro.github.io/ocaml-cheat-sheets/tuareg-mode.pdf) )
12 |
13 | ## In development
14 |
15 | * ocaml-c-api : The C foreign interface of OCaml
16 | * ocaml-libs : OCaml libraries available
17 |
--------------------------------------------------------------------------------
/common/cheat-style.sty:
--------------------------------------------------------------------------------
1 | \usepackage[T1]{fontenc}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 | \usepackage{epsfig}
7 | \usepackage[scaled=0.8]{DejaVuSansMono}
8 | \usepackage{upquote} % Uncurly the quotes
9 | \usepackage{fancyvrb} % better verbatim
10 | \usepackage{etoolbox} % for backquote fix
11 | \usepackage{mdframed} % nice frames
12 | \usepackage[nobottomtitles]{titlesec} % better titles
13 | \usepackage{enumitem}
14 | \setlist[itemize]{noitemsep, topsep=0pt}
15 |
16 | % backquote dejavu fix
17 | \makeatletter
18 | \chardef\straightquote@code=\catcode`'
19 | \chardef\backquote@code=\catcode``
20 | \catcode`'=\active \catcode``=\active
21 | \patchcmd{\@noligs}
22 | {\textasciigrave}
23 | {\fixedtextasciigrave}
24 | {}{}
25 | \newcommand{\fixedtextasciigrave}{%
26 | \makebox[.5em]{\fontencoding{TS1}\fontfamily{fvs}\selectfont\textasciigrave}% Vera Sans
27 | }
28 | \catcode\lq\'=\straightquote@code
29 | \catcode\lq\`=\backquote@code
30 | \makeatletter
31 |
32 |
33 |
34 | % fancyvrb and mdframed stuff
35 | \newmdenv[bottomline=false,rightline=false]{topleft}
36 | \newmdenv[topline=false,leftline=false]{bottomright}
37 | \DefineVerbatimEnvironment{Verbacorner}{Verbatim}{}
38 | \surroundwithmdframed[bottomline=false,rightline=false]{Verbacorner}
39 | \fvset{commandchars=@\{\}}
40 |
41 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
42 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
43 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
44 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
45 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
46 | }
47 | \pagestyle{empty}
48 | \makeatletter
49 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
50 | {-1ex plus -.5ex minus -.2ex}%
51 | {0.5ex plus .2ex}%x
52 | {\normalfont\large\bfseries}}
53 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
54 | {-1ex plus -.5ex minus -.2ex}%
55 | {0.5ex plus .2ex}%
56 | {\normalfont\normalsize\bfseries}}
57 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
58 | {-1ex plus -.5ex minus -.2ex}%
59 | {1ex plus .2ex}%
60 | {\normalfont\small\bfseries}}
61 | \makeatother
62 |
63 | % Define BibTeX command
64 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
65 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
66 |
67 | % Don't print section numbers
68 | \setcounter{secnumdepth}{0}
69 |
70 |
71 | \setlength{\parindent}{0pt}
72 | \setlength{\parskip}{0pt plus 0.5ex}
73 |
74 | \newcommand{\makeheader}[1]
75 | {
76 | \hspace{-2em}
77 | \begin{tabular}{l}
78 | \vspace{0cm}\epsfig{file=../licence/by-sa,width=24mm}\\
79 | \end{tabular}\vspace{-2mm}
80 | \hfill
81 | \hfill
82 | \Large{\textbf{#1}}
83 | \hfill
84 | \hfill
85 | \scriptsize
86 | OCaml v.4.08.1 ---
87 | Revision 2 ---
88 | Copyright \copyright\ 2019 OCamlPro SAS
89 | ---
90 | {\bf http://www.ocamlpro.com/}\\
91 | \hrule~\\
92 | \raggedright
93 | \footnotesize
94 |
95 | }
96 |
97 | \newenvironment{absolutelynopagebreak}
98 | {\par\nobreak\vfil\penalty0\vfilneg
99 | \vtop\bgroup}
100 | {\par\xdef\tpd{\the\prevdepth}\egroup
101 | \prevdepth=\tpd}
102 |
103 | \newcommand{\vb}{\usefont{T1}{DejaVuSansMono-TLF}{b}{n}}
104 |
105 | \newenvironment{libcomments}{\begin{itemize}[topsep=-10000pt]}{\end{itemize}}
106 |
--------------------------------------------------------------------------------
/common/fig/ocamlpro_carre_bleu.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/common/fig/ocamlpro_carre_bleu.pdf
--------------------------------------------------------------------------------
/common/fig/ocamlpro_carre_noir.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/common/fig/ocamlpro_carre_noir.pdf
--------------------------------------------------------------------------------
/common/ocaml-cs.cls:
--------------------------------------------------------------------------------
1 | \NeedsTeXFormat{LaTeX2e}
2 | % Arguments are : nbcode/colcode
3 | \ProvidesClass{ocaml-cs}
4 |
5 | % Based on article class
6 | \LoadClass{article}
7 | % Packages
8 | \RequirePackage[T1]{fontenc}
9 | \RequirePackage{multicol}
10 | \RequirePackage{calc}
11 | \RequirePackage{ifthen}
12 | \RequirePackage{epsfig}
13 | \RequirePackage{upquote} % Uncurly the quotes
14 | \RequirePackage[scaled=0.8]{DejaVuSans}
15 | \RequirePackage[scaled=0.8]{DejaVuSansMono}
16 | \RequirePackage{mdframed} % nice frames
17 | \RequirePackage[nobottomtitles]{titlesec} % better titles
18 | \RequirePackage{enumitem}
19 | \setlist[itemize]{noitemsep, topsep=0pt}
20 |
21 | % page setting
22 | \RequirePackage[a4paper,landscape,margin=1cm,includehead,headsep=2ex,nofoot]{geometry}
23 |
24 | \setlength{\headheight}{20.1pt}
25 | \setlength{\headsep}{10pt}
26 |
27 |
28 | % multicol parameters
29 | % These lengths are set only within the two main columns
30 | %\setlength{\columnseprule}{0.25pt}
31 | %\setlength{\premulticols}{1pt}
32 | %\setlength{\postmulticols}{1pt}
33 | %\setlength{\multicolsep}{1pt}
34 | %\setlength{\columnsep}{5pt}
35 |
36 | \renewcommand{\familydefault}{\sfdefault} % everything sans-serif
37 | % \renewcommand{\rmdefault}{garamond}
38 |
39 | %Url handling
40 | \RequirePackage{hyperref}
41 | \hypersetup{
42 | colorlinks=true,
43 | urlcolor=black,
44 | linkcolor=black,
45 | citecolor=black
46 | }
47 |
48 | %%%%%%%%%%%%%%%%%%%%%%%%%%
49 | % Page & main style %
50 | %%%%%%%%%%%%%%%%%%%%%%%%%%
51 |
52 | \RequirePackage{fancyhdr}
53 | \pagestyle{fancy}
54 | \newcommand{\makeheader}[3]{
55 | \fancyhead[L]{
56 | \begin{minipage}{150pt}
57 | \includegraphics[width=24mm]{../licence/by-sa.pdf}
58 | \end{minipage}
59 | }
60 | \fancyhead[C]{
61 | \Large{#1}
62 | }
63 | \fancyhead[R]{
64 | {\scriptsize
65 | #2 $\cdot$ Revision #3 \copyright\ 2019 $\quad$
66 | \begin{minipage}{30pt}
67 | \vspace{-3pt}
68 | \includegraphics[width=\textwidth]{\logoOCP} %defined at bottom
69 | \end{minipage}
70 | }}
71 | \fancyfoot[L]{}
72 | \fancyfoot[C]{}
73 | \fancyfoot[R]{}
74 | }
75 |
76 | % font size -> set to equivalent to footnotesize of 10 pt
77 | % it affect only the \\normalsize command, all are still relative to default's
78 | % article one (10pt)
79 | \newcommand\articlenormalsize{\fontsize{10pt}{12pt}\selectfont}
80 | \renewcommand\normalsize{\footnotesize}
81 |
82 | % redefine sections padding
83 | \makeatletter
84 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
85 | {-1ex plus -.5ex minus -.2ex}%
86 | {0.5ex}%
87 | {\normalfont\large\bfseries}}
88 | \renewcommand{\subsection}{\@startsection{subsection}{2}{4mm}%
89 | {-1ex}%
90 | {0.5ex}%
91 | {\normalfont\articlenormalsize\bfseries}}
92 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{16mm}%
93 | {-1ex plus -.5ex minus -.2ex}%
94 | {1ex plus .2ex}%
95 | {\normalfont\small\bfseries}}
96 | \makeatother
97 |
98 | %\pagestyle{empty}
99 | % set section counter to 0
100 | \setcounter{secnumdepth}{0}
101 | % set padding of indent & skip
102 | \setlength{\parindent}{0pt}
103 | \setlength{\parskip}{0.5ex}
104 | \renewcommand{\smallskip}{\vspace{0.25ex}}
105 |
106 | % Text at right
107 | \raggedright
108 |
109 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 |
111 | %Define some colors
112 | \RequirePackage{color}
113 | \definecolor{cinnamon}{rgb}{0.82, 0.41, 0.12}
114 | \definecolor{gray05}{gray}{0.05}
115 | \definecolor{gray20}{gray}{0.20}
116 | \definecolor{gray25}{gray}{0.25}
117 | \definecolor{gray30}{gray}{0.30}
118 | \definecolor{gray40}{gray}{0.40}
119 | \definecolor{gray50}{gray}{0.50}
120 | \definecolor{gray75}{gray}{0.75}
121 | \definecolor{persiangreen}{rgb}{0.0, 0.65, 0.58}
122 | \definecolor{pinegreen}{rgb}{0.0, 0.47, 0.44}
123 | \definecolor{richblack}{rgb}{0.0, 0.25, 0.25}
124 | \definecolor{tenne}{rgb}{0.8, 0.34, 0.0}
125 | \definecolor{tyrianpurple}{rgb}{0.4, 0.01, 0.24}
126 | \definecolor{vermilion}{rgb}{0.89, 0.26, 0.2}
127 | \definecolor{deepjunglegreen}{rgb}{0.0, 0.29, 0.29}
128 |
129 | \newcommand\opam{\textsf{opam}~}
130 |
131 | % verbatim
132 | \RequirePackage{fancyvrb} % better verbatim
133 | \newmdenv[bottomline=false,rightline=false]{topleft}
134 | \newmdenv[topline=false,leftline=false]{bottomright}
135 | \DefineVerbatimEnvironment{Verbacorner}{Verbatim}{}
136 | \surroundwithmdframed[bottomline=false,rightline=false]{Verbacorner}
137 | \fvset{commandchars=@\{\}}
138 |
139 | \newenvironment{absolutelynopagebreak}
140 | {\par\nobreak\vfil\penalty0\vfilneg
141 | \vtop\bgroup}
142 | {\par\xdef\tpd{\the\prevdepth}\egroup
143 | \prevdepth=\tpd}
144 |
145 | \newcommand{\vb}[1]{{\usefont{T1}{DejaVuSansMono-TLF}{b}{n} #1}}
146 |
147 | \newenvironment{libcomments}{\begin{itemize}[topsep=-10000pt]}{\end{itemize}}
148 |
149 | % tabulrax package, needed for breaking newlines without setting the columns
150 | % size
151 | \RequirePackage{tabularx}
152 |
153 | % table for code vs explanation
154 | % X column type if for breaking line (tabularx)
155 | % \extracolsep defines the padding size when set (0 for the fst, 5pt for the snd)
156 | \newcommand\listvav[1]{
157 | \vspace{\parskip}
158 | \begin{tabularx}{\dimexpr\columnwidth-.33\columnsep}{@{}l@{\extracolsep{5pt}}>{\raggedright\arraybackslash}X@{}}
159 | #1
160 | \end{tabularx}
161 | \vspace{\parskip}
162 | }
163 |
164 | % Command to indent once
165 | % As the way to deactive paragraph indentation is to set size of \indent to 0,
166 | % also ragged right deactivate indentation, we can't use it. Redefining then a
167 | % new indent command manually \dnet because c'est un \dent
168 | \newcommand\dent{\hspace{10pt}}
169 |
170 | % Within \listvav, for long comments: comment on the next line, left-indented
171 | % e.g. \splt{\lst!command!}{long comment like a paragraph} \\
172 | \newcommand\splt[2]{
173 | \multicolumn{2}{@{\extracolsep{0pt}}l}{#1} \\
174 | \multicolumn{2}{@{\dent\extracolsep{0pt}}>{\raggedright\hsize=\dimexpr\columnwidth-.33\columnsep-16pt\relax}X}{#2}
175 | }
176 | % Within \listvav, for long commands: put on its own line
177 | % e.g. \linecmd{\lst!long text!} & comment aligned below \\
178 | \newcommand\linecmd[1]{
179 | \multicolumn{2}{@{\extracolsep{0pt}}l}{#1} \\
180 | }
181 |
182 | %% CODE
183 | \RequirePackage{listings}
184 |
185 | \lstdefinelanguage{neutral}{
186 | keywords={};
187 | }
188 |
189 | %Define opam keywords
190 | \lstdefinelanguage{opam}{
191 | alsoletter={-},
192 | keywords={opam},
193 | % commands
194 | keywords=[2]{
195 | clean,
196 | config,
197 | env,
198 | exec,
199 | init,
200 | install,
201 | lint,
202 | list,
203 | lock,
204 | pin,
205 | reinstall,
206 | remove,
207 | repository,
208 | show,
209 | source,
210 | switch,
211 | unpin,
212 | update,
213 | upgrade,
214 | var,
215 | % plugins
216 | depext,
217 | publish,
218 | },
219 | % subcommands
220 | keywords=[3]{
221 | add,
222 | add-constraint,
223 | cache,
224 | create,
225 | edit,
226 | export,
227 | filter,
228 | import,
229 | index,
230 | list-available,
231 | report,
232 | set,
233 | set-global,
234 | set-repos,
235 | set-url,
236 | },
237 | % generic arguments names
238 | keywords=[4]{
239 | args,
240 | command,
241 | compiler,
242 | dir,
243 | flds,
244 | name,
245 | patterns,
246 | pkg,
247 | pkgs,
248 | rank,
249 | root,
250 | sw,
251 | url,
252 | v,
253 | val,
254 | version,
255 | file
256 | },
257 | % plugins
258 | keywords=[5]{
259 | },
260 | }
261 |
262 | %Define opam keywords
263 | \lstdefinelanguage{opam-file}{
264 | alsoletter={-:},
265 | string=[b]{"""},
266 | string=[b]{"},
267 | keepspaces,
268 | showstringspaces=false,
269 | comment=[l]\#,
270 | % fields
271 | keywords=[3]{
272 | version:,
273 | opam-version:,
274 | name:,
275 | version:,
276 | synopsis:,
277 | description:,
278 | maintainer:,
279 | authors:,
280 | license:,
281 | homepage:,
282 | bug-reports:,
283 | dev-repo:,
284 | depends:,
285 | build:,
286 | install:,
287 | depopts:,
288 | pin-depends:,
289 | extra-sources:,
290 | extra-files:,
291 | depexts:,
292 | tags:,
293 | substs:,
294 | patches:,
295 | run-test:,
296 | pin-depends:,
297 | conflicts:,
298 | available:,
299 | build-env:,
300 | flags:,
301 | post-messages:,
302 | % sections
303 | url,
304 | extra-source,
305 | % not "opam" fields, for .opam/config
306 | global-variables:,
307 | eval-variables:,
308 | },
309 | % variables
310 | keywords=[5]{
311 | true,false,
312 | %global
313 | opam-version,root,jobs,make,arch,os,os-distribution,os-family,os-version,
314 | %switch
315 | switch,user,group,prefix,lib,bin,sbin,share,doc,etc,man,toplevel,stublibs,
316 | %package
317 | name,version,depends,installed,enable,pinned,build,hash,dev,build-id,
318 | bin,sbin,lib,man,doc,share,etc,
319 | %depends
320 | with-test,with-doc,build,post,
321 | },
322 | % placeholders
323 | keywords=[4]{
324 | bool-var,
325 | cmds,
326 | condition,
327 | deps,
328 | pkg,
329 | undef,
330 | var,
331 | },
332 | }
333 |
334 | \lstset{
335 | basicstyle=\usefont{T1}{DejaVuSansMono-TLF}{m}{n}\color{gray25},
336 | escapeinside={@<}{>@},
337 | aboveskip=\parskip,
338 | }
339 |
340 | % alias for lstinline
341 | %\lstMakeShortInline[language=opam]!
342 | \newcommand\lst\lstinline
343 |
344 | %%% OPTIONS /!\ need to be at bottom of cls
345 | % Option `nbcode`
346 | \DeclareOption{nbcode}{
347 | \lstset{
348 | keywordstyle=\color{gray25},
349 | keywordstyle=[2]\bfseries\color{gray05},
350 | keywordstyle=[3]\bfseries\color{gray25},
351 | keywordstyle=[4]\itshape,
352 | keywordstyle=[5]\color{gray25},
353 | commentstyle=\color{gray50},
354 | stringstyle=\itshape\color{gray25},
355 | }
356 |
357 | \newcommand\logoOCP{../common/fig/ocamlpro_carre_noir.pdf}
358 | }
359 |
360 | % Option `colcode`
361 | \DeclareOption{colcode}{
362 | \lstset{
363 | keywordstyle=\bfseries\color{gray50},
364 | keywordstyle=[2]\bfseries\color{tenne},
365 | keywordstyle=[3]\bfseries\color{pinegreen},
366 | keywordstyle=[4]\itshape\color{black},
367 | keywordstyle=[5]\color{tyrianpurple},
368 | commentstyle=\color{tenne},
369 | stringstyle=\itshape\color{gray50},
370 | }
371 |
372 | \newcommand\logoOCP{../common/fig/ocamlpro_carre_bleu.pdf}
373 | }
374 |
375 | % Execute class options
376 | \ProcessOptions\relax
377 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | OCaml Cheat Sheets
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
OCaml Cheat Sheets
26 |
27 |
40 |
41 |
42 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/docs/ocaml-c-api.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-c-api.pdf
--------------------------------------------------------------------------------
/docs/ocaml-lang.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-lang.pdf
--------------------------------------------------------------------------------
/docs/ocaml-libs.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-libs.pdf
--------------------------------------------------------------------------------
/docs/ocaml-opam-bw.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-opam-bw.pdf
--------------------------------------------------------------------------------
/docs/ocaml-opam.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-opam.pdf
--------------------------------------------------------------------------------
/docs/ocaml-stdlib.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-stdlib.pdf
--------------------------------------------------------------------------------
/docs/ocaml-tools.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/ocaml-tools.pdf
--------------------------------------------------------------------------------
/docs/tuareg-mode.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/docs/tuareg-mode.pdf
--------------------------------------------------------------------------------
/licence/by-sa.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/licence/by-sa.pdf
--------------------------------------------------------------------------------
/ocaml-c-api/Makefile:
--------------------------------------------------------------------------------
1 | FILE=ocaml-c-api
2 |
3 | $(FILE).pdf: $(FILE).tex
4 | pdflatex $(FILE).tex
5 |
6 | view: $(FILE).pdf
7 | evince $(FILE).pdf &
8 |
9 | clean:
10 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
11 |
--------------------------------------------------------------------------------
/ocaml-c-api/ocaml-c-api.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 | \usepackage{epsfig}
7 |
8 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
9 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
10 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
11 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
12 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
13 | }
14 | \pagestyle{empty}
15 | \makeatletter
16 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
17 | {-1ex plus -.5ex minus -.2ex}%
18 | {0.5ex plus .2ex}%x
19 | {\normalfont\large\bfseries}}
20 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
21 | {-1explus -.5ex minus -.2ex}%
22 | {0.5ex plus .2ex}%
23 | {\normalfont\normalsize\bfseries}}
24 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
25 | {-1ex plus -.5ex minus -.2ex}%
26 | {1ex plus .2ex}%
27 | {\normalfont\small\bfseries}}
28 | \makeatother
29 |
30 | % Define BibTeX command
31 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
32 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
33 |
34 | % Don't print section numbers
35 | \setcounter{secnumdepth}{0}
36 |
37 |
38 | \setlength{\parindent}{0pt}
39 | \setlength{\parskip}{0pt plus 0.5ex}
40 |
41 |
42 | % -----------------------------------------------------------------------
43 |
44 | \begin{document}
45 |
46 | \setlength{\premulticols}{1pt}
47 | \setlength{\postmulticols}{1pt}
48 | \setlength{\multicolsep}{1pt}
49 | \setlength{\columnsep}{3mm}
50 |
51 | \hspace{-2em}
52 | \begin{tabular}{l}
53 | \vspace{0cm}\epsfig{file=../licence/by-sa,width=24mm}\\
54 | \end{tabular}\vspace{-2mm}
55 | \hfill
56 | \hfill
57 | \Large{\textbf{OCaml --- C API}}
58 | \hfill
59 | \hfill
60 | \scriptsize
61 | OCaml v. 3.12.0 ---
62 | \today{} ---
63 | Copyright \copyright\ 2011 OCamlPro SAS
64 | ---
65 | {\bf http://www.ocamlpro.com/}\\
66 | \hrule~\\
67 | \raggedright
68 | \footnotesize
69 | \begin{multicols}{3}
70 |
71 | \vbox{
72 | \section{Declaring Primitives}
73 |
74 | 1 to 5 arguments:\\
75 | {\tt external} \emph{ocamlfun} {\tt :} \emph{ocamltype} {\tt =} \verb!"!c\_stub\verb!"!
76 |
77 | more than 5 arguments:\\
78 | {\tt external} \emph{ocamlfun} {\tt :} \emph{ocamltype} {\tt =} \verb!"!tupled\_C\_stub\verb!"! \verb!"!c\_stub\verb!"!
79 |
80 | The C\_stub function has as many arguments as the OCaml function, while
81 | tupled\_C\_stub has the C prototype:\\
82 |
83 | {\tt CAMLprim value} tuple\_c\_stub\verb!(value * argv, int argn)!
84 |
85 | where \verb!argn! is the number of values stored in \verb!argv!.
86 |
87 | \section{Include Files}
88 | \begin{tabular}{ll}
89 | {\tt caml/mlvalues.h} & value type, and conversion macros \\
90 | {\tt caml/alloc.h} & allocation functions \\
91 | {\tt caml/memory.h} & memory-related functions and macros \\
92 | {\tt caml/fail.h} & functions for raising exceptions \\
93 | {\tt caml/callback.h} & callback from C to OCaml \\
94 | {\tt caml/custom.h} & operations on custom blocks \\
95 | {\tt caml/intext.h} & de/serialization for custom blocks \\
96 | \end{tabular}
97 |
98 | \section{Linking with C code}
99 |
100 | \subsection{Static Linking}
101 |
102 | \verb!-custom!
103 |
104 | \subsection{Dynamic Linking}
105 |
106 | \verb!.so! and \verb!.dll!
107 |
108 | \section{Value Representation}
109 |
110 | The {\tt value} type is either (1) an unboxed integer, (2) a pointer
111 | to a block inside the OCaml heap, or (3) a pointer outside the OCaml
112 | heap (not scanned by GC).
113 |
114 | A {\tt value} pointing within OCaml heap should always point to the
115 | beginning of an OCaml block.
116 |
117 | Integers are encoded as $(n$\verb!< enum! & GADT constructor \\
54 | ~~~ \Verb!| Inlined of @{ x : int @}! & Inline record \\
55 | \end{tabular}
56 |
57 | \subsection{Constructed Values}
58 |
59 | \begin{Verbatim}
60 | let r = @{ field1 = true; field2 = 3; @}
61 | let r' = @{ r with field1 = false @}
62 | r.field2 <- r.field2 + 1;
63 | let c = Constant
64 | let c = Param "foo"
65 | let c = Pair ("bar",3)
66 | let c = Gadt 0
67 | let c = Inlined @{ x = 3 @}
68 | \end{Verbatim}
69 |
70 | \subsection{References, Strings and Arrays}
71 |
72 | \begin{tabular}{ll}
73 | \Verb!let x = ref 3! & integer reference (mutable) \\
74 | \Verb!x := 4! & reference assignation \\
75 | \verb&print_int !x;& & reference access \\
76 | \Verb!s.[0]! & string char access \\
77 | \Verb!t.(0)! & array element access \\
78 | \Verb!t.(0) <- x! & array element modification \\
79 | \end{tabular}
80 |
81 | \subsection{Imports --- Namespaces}
82 |
83 | \begin{tabular}{ll}
84 | \Verb!open Unix! & global open \\
85 | \Verb!let open Unix in! \emph{expr} & local open \\
86 | \Verb!Unix.(!\emph{expr}\Verb!)! & local open \\
87 | \end{tabular}
88 |
89 | \vbox{
90 | \subsection{Functions}
91 |
92 | \begin{tabular}{ll}
93 | \Verb!let f x =! \emph{expr} & function with one arg \\
94 | \Verb!let rec f x =! \emph{expr} & recursive function \\
95 | \hfill apply:& \Verb!f x! \\
96 | \Verb!let f x y =! \emph{expr} & with two args \\
97 | \hfill apply:& \Verb!f x y! \\
98 | \Verb!let f (x,y) =! \emph{expr} & with a pair as arg\\
99 | \hfill apply: & \Verb!f (x,y)! \\
100 | \Verb!List.iter (fun x ->! \emph{expr}\Verb!) l! & anonymous function\\
101 | \Verb!let f= function None ->! \emph{act}& function definition\\
102 | \Verb! | Some x ->! \emph{act}& \qquad [by cases]\\
103 | \hfill apply: & \Verb!f (Some x)! \\
104 | \Verb!let f ~str ~len =! \emph{expr} & with labeled args \\
105 | \hfill apply: & \Verb!f ~str:s ~len:10! \\
106 | \hfill apply (for \Verb!~str:str!): & \Verb!f ~str ~len! \\
107 | \Verb!let f ?len ~str =! \emph{expr} & with optional arg (\Verb!option!) \\
108 | \Verb!let f ?(len=0) ~str =! \emph{expr} & optional arg default \\
109 | \hfill apply (with omitted arg): & \Verb!f ~str:s ! \\
110 | \hfill apply (with commuting): & \Verb!f ~str:s ~len:12! \\
111 | \hfill apply (\Verb!len: int option!): & \Verb!f ?len ~str:s! \\
112 | \hfill apply (explicitly omitted): & \Verb!f ?len:None ~str:s! \\
113 | \Verb!let f (x : int) =! \emph{expr} & arg has constrainted type \\
114 | \Verb!let f : 'a 'b. 'a*'b -> 'a!& function with constrainted\\
115 | \Verb! = fun (x,y) -> x! & \hfill polymorphic type\\
116 | \end{tabular}
117 |
118 |
119 | \subsection{Modules}
120 |
121 | \begin{tabular}{ll}
122 | \Verb!module M = struct! .. \Verb!end! & module definition\\
123 | \Verb!module M: sig! .. \Verb!end= struct! .. \Verb!end! & module and signature\\
124 | \Verb!module M = Unix! & module renaming \\
125 | \Verb!include M! & include items from \\
126 | \Verb!module type Sg = sig! .. \Verb!end! & signature definition\\
127 | \Verb!module type Sg = module type of M! & signature of module\\
128 | \Verb!let module M = struct! .. \Verb!end in! .. & local module \\
129 | \Verb!let m = (module M : Sg)! & to $1^{st}$-class module\\
130 | \Verb!module M = (val m : Sg)! & from $1^{st}$-class module\\
131 | \Verb!module Make(S: Sg) = struct! .. \Verb!end! & functor \\
132 | \Verb!module M = Make(M')! & functor application \\
133 | & \\
134 | \end{tabular}
135 |
136 | Module type items: \Verb!val!, \Verb!external!, \Verb!type!, \Verb!exception!, \Verb!module!, \Verb!open!, \Verb!include!, \Verb!class!
137 |
138 | \subsection{Pattern-matching}
139 |
140 | \begin{tabular}{ll}
141 | \Verb!match! \emph{expr} \Verb!with! \\
142 | \Verb! |! \emph{pattern} \Verb!->! \emph{action}\\
143 | \Verb! |! \emph{pattern} \Verb!when! \emph{guard} \Verb!->! \emph{action}
144 | & conditional case \\
145 | \Verb! | _ ->! \emph{action} & default case\\
146 | \end{tabular}
147 | Patterns:\\
148 | \begin{tabular}{ll}
149 | \Verb!| Pair (x,y) ->! & variant pattern \\
150 | \Verb!| @{ field = 3; _ @} ->! & record pattern \\
151 | \Verb!| head :: tail ->! & list pattern \\
152 | \Verb!| [1;2;x] ->! & list pattern \\
153 | \Verb!| (Some x) as y ->! & with extra binding \\
154 | \Verb!| (1,x) | (x,0) ->! & or-pattern \\
155 | \Verb!| exception! \emph{exn} \Verb!->! & try\&match \\
156 | \end{tabular}
157 | }
158 |
159 | \vbox{
160 | \subsection{Conditionals}
161 |
162 | Do NOT use on closures
163 |
164 | \vspace{1pt}
165 |
166 | \begin{tabular}{c|c|l}
167 | Structural & Physical & \\
168 | \hline
169 | \Verb!=! & \Verb!==! & Polymorphic Equality \\
170 | \Verb!<>! & \verb&!=& & Polymorphic Inequality \\
171 | \end{tabular}
172 |
173 | Polymorphic Generic Comparison Function: \Verb!compare!
174 | \begin{tabular}{l|c|c|c}
175 | & x $<$ y & x $=$ y & x $>$ y \\
176 | \hline
177 | \Verb!compare x y! & negative & 0 & positive \\
178 | \end{tabular}
179 |
180 | Other Polymorphic Comparisons: \Verb!>!, \Verb!>=!, \Verb! ...! & \hspace{3pt} if raised in \emph{expr} \\
201 | \end{tabular}
202 |
203 | \subsection{Objects and Classes}
204 |
205 | \begin{tabular}{ll}
206 | \Verb!class virtual foo x = !& virtual class with arg \\
207 | \Verb! let y = x+2 in! & init before object creation\\
208 | \Verb! object (self: 'a)! & object with self reference\\
209 | \Verb! val mutable variable = x! & mutable instance variable \\
210 | \Verb! method get = variable! & accessor \\
211 | \Verb! method set z =!\\
212 | \Verb! variable <- z+y! & mutator\\
213 | \Verb! method virtual copy : 'a! & virtual method\\
214 | \Verb! initializer! & init after object creation\\
215 | \Verb! self#set (self#get+1)!& \\
216 | \Verb! end! & \\
217 | \Verb!class bar = !& non-virtual class\\
218 | \Verb! let var = 42 in! & class variable\\
219 | \Verb! fun z -> object! & constructor argument \\
220 | \verb& inherit foo z as super& & inheritance and ancestor reference\\
221 | \verb& method! set y =& & method explicitly overridden\\
222 | \Verb! super#set (y+4)! & access to ancestor \\
223 | \Verb! method copy = @{< x = 5 >@}! & copy with change \\
224 | \Verb!end! & \\
225 | \Verb!let obj = new bar 3! & new object \\
226 | \Verb!obj#set 4; obj#get! & method invocation \\
227 | \Verb!let obj = object! .. \Verb!end! & immediate object \
228 | \end{tabular}
229 |
230 | \subsection{Polymorphic variants}
231 |
232 |
233 | \begin{tabular}{ll}
234 | \Verb!type t = [ `A | `B of int ]! & closed variant \\
235 | \Verb!type u = [ `A | `C of float ]! & \\
236 | \Verb!type v = [ t | u | ]! & union of variants \\
237 | \Verb!let f : [< t ] -> int = function! & argument must be\\
238 | \Verb! | `A -> 0 | `B n -> n! & \hfill a subtype of \Verb!t!\\
239 | \Verb!let f : [> t ] -> int = function! & \Verb!t! is a subtype \\
240 | \Verb! | `A -> 0 | `B n -> n | _ -> 1! & \hfill of the argument \\
241 | \end{tabular}
242 |
243 | \end{multicols}
244 |
245 |
246 | \end{document}
247 |
248 | %%% Local Variables:
249 | %%% mode: latex
250 | %%% TeX-master: t
251 | %%% End:
252 |
--------------------------------------------------------------------------------
/ocaml-libs/Makefile:
--------------------------------------------------------------------------------
1 | PDF_VIEWER = evince
2 |
3 | ocaml-libs.pdf: ocaml-libs.tex
4 | pdflatex ocaml-libs.tex
5 |
6 | view: ocaml-libs.pdf
7 | $(PDF_VIEWER) ocaml-libs.pdf
8 |
9 | clean:
10 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
11 |
--------------------------------------------------------------------------------
/ocaml-libs/ocaml-libs.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 | \usepackage{epsfig}
7 |
8 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
9 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
10 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
11 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
12 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
13 | }
14 | \pagestyle{empty}
15 | \makeatletter
16 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
17 | {-1ex plus -.5ex minus -.2ex}%
18 | {0.5ex plus .2ex}%x
19 | {\normalfont\large\bfseries}}
20 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
21 | {-1explus -.5ex minus -.2ex}%
22 | {0.5ex plus .2ex}%
23 | {\normalfont\normalsize\bfseries}}
24 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
25 | {-1ex plus -.5ex minus -.2ex}%
26 | {1ex plus .2ex}%
27 | {\normalfont\small\bfseries}}
28 | \makeatother
29 |
30 | % Define BibTeX command
31 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
32 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
33 |
34 | % Don't print section numbers
35 | \setcounter{secnumdepth}{0}
36 |
37 |
38 | \setlength{\parindent}{0pt}
39 | \setlength{\parskip}{0pt plus 0.5ex}
40 |
41 |
42 | % -----------------------------------------------------------------------
43 |
44 | \begin{document}
45 | \hspace{-2em}
46 | \begin{tabular}{l}
47 | \vspace{0cm}\epsfig{file=../licence/by-sa,width=24mm}\\
48 | \end{tabular}\vspace{-2mm}
49 | \hfill
50 | \hfill
51 | \Large{\textbf{OCaml Libraries}}
52 | \hfill
53 | \hfill
54 | \scriptsize
55 | OCaml v. 4.01.0 ---
56 | \today{} ---
57 | Copyright \copyright\ 2013 OCamlPro SAS
58 | ---
59 | {\bf http://www.ocamlpro.com/}\\
60 | \hrule~\\
61 | \raggedright
62 | \footnotesize
63 | \begin{multicols}{3}
64 |
65 | % multicol parameters
66 | % These lengths are set only within the two main columns
67 | %\setlength{\columnseprule}{0.25pt}
68 | \setlength{\premulticols}{1pt}
69 | \setlength{\postmulticols}{1pt}
70 | \setlength{\multicolsep}{1pt}
71 | \setlength{\columnsep}{2pt}
72 |
73 | \section{Extend the Standard Library}
74 |
75 | \begin{tabular}{lp{7cm}}
76 | - OCaml Batteries Included: a comprehensive standard library\\
77 | \verb! http://batteries.forge.ocamlcore.org/!\\
78 | - OCaml ExtLib: extended standard library\\
79 | \verb! http://code.google.com/p/ocaml-extlib/!\\
80 | - Jane Street's Core: industrial strength library\\
81 | \verb! https://github.com/janestreet/core!\\
82 | \end{tabular}
83 |
84 | \section{XML Libraries}
85 |
86 | \begin{tabular}{lp{7cm}}
87 | - xml-light: Simple and easy to use\\
88 | \verb! http://tech.motion-twin.com/xmllight.html!\\
89 | - xmlm: Powerful and averagely easy to use\\
90 | \verb! http://erratique.ch/software/xmlm!\\
91 | - Tyxml: type-safe Xml trees\\
92 | \verb! http://ocsigen.org/tyxml/!\\
93 | \end{tabular}
94 |
95 | \section{JSon Libraries}
96 |
97 | \begin{tabular}{lp{7cm}}
98 | - Yojson: parsing and printing library\\
99 | \verb! http://mjambon.com/yojson.html!\\
100 | - Jsonm: describe me\\
101 | \verb! http://erratique.ch/software/jsonm!\\
102 | \end{tabular}
103 |
104 | \section{Serialise / Deserialise}
105 |
106 | \begin{tabular}{lp{7cm}}
107 | - Sexplib: convert OCaml values to S-expressions\\
108 | - Atdgen: serialise, deserialise with Json format\\
109 | \verb! https://github.com/mjambon/atdgen!\\
110 | \end{tabular}
111 |
112 | \section{Binary Data}
113 |
114 | \begin{tabular}{lp{7cm}}
115 | - Biniou: binary data formatting\\
116 | \verb! http://mjambon.com/biniou.html!\\
117 | \end{tabular}
118 |
119 | \section{Unit Testing}
120 |
121 | \begin{tabular}{lp{7cm}}
122 | - OUnit: easy create unit-tests similar to HUnit (for Haskell)\\
123 | \verb! http://ounit.forge.ocamlcore.org/!\\
124 | \end{tabular}
125 |
126 | \section{Networking}
127 |
128 | \begin{tabular}{lp{7cm}}
129 | - OCamlNet: describe me\\
130 | \verb! http://projects.camlcity.org/projects/ocamlnet.html!\\
131 | - ocurl: interface for the C libcurl\\
132 | \verb! http://sourceforge.net/projects/ocurl/!\\
133 | \end{tabular}
134 |
135 | \section{Parser}
136 |
137 | \begin{tabular}{lp{7cm}}
138 | - Menhir: a LR(1) parser generator\\
139 | \verb! http://pauillac.inria.fr/~fpottier/menhir/!\\
140 | \end{tabular}
141 |
142 | \section{Regular Expressions}
143 |
144 | \begin{tabular}{lp{7cm}}
145 | - pcre-ocaml: bindings to the PCRE library\\
146 | \verb! https://bitbucket.org/mmottl/pcre-ocaml!\\
147 | - ocaml-re: pure OCaml lib, supports Perl and POSIX-style\\
148 | \verb! https://github.com/ocaml/ocaml-re!\\
149 | - Mikmatch: pattern matching with regexps\\
150 | \verb! http://mjambon.com/micmatch.html!\\
151 | \end{tabular}
152 |
153 | \section{Databases}
154 |
155 | \begin{tabular}{lp{7cm}}
156 | - postgresql-ocaml: PostgreSQL bindings\\
157 | \verb! https://bitbucket.org/mmottl/postgresql-ocaml!\\
158 | - ocaml-mysql: bindings for interacting with MySQL databases\\
159 | \verb! http://ocaml-mysql.forge.ocamlcore.org/!\\
160 | - CamlDBM: binding to NDBM/GDBM databases\\
161 | \verb! https://forge.ocamlcore.org/projects/camldbm/!\\
162 | \end{tabular}
163 |
164 | \section{Graphical User Interfaces}
165 |
166 | \begin{tabular}{lp{7cm}}
167 | - LablGtk: interface to GTK\\
168 | \verb! http://lablgtk.forge.ocamlcore.org/!\\
169 | - ocplib-wxOCaml: bindings to WxWidgets\\
170 | \verb! http://www.typerex.org/ocplib-wxOCaml.html!\\
171 | \end{tabular}
172 |
173 | \section{Threads}
174 |
175 | \begin{tabular}{lp{7cm}}
176 | - lwt: cooperative light-weight threads\\
177 | \verb! http://ocsigen.org/lwt/!\\
178 | \end{tabular}
179 |
180 | \section{Parallelisation}
181 |
182 | \begin{tabular}{lp{7cm}}
183 | - parmap: describe me\\
184 | \end{tabular}
185 |
186 | \section{Profiling}
187 |
188 | \begin{tabular}{lp{7cm}}
189 | - ocamlviz: real-time profiling tool\\
190 | \end{tabular}
191 | % http://ocaml-benchmark.forge.ocamlcore.org/ ?
192 |
193 | \section{Extend with Scripting}
194 |
195 | \begin{tabular}{lp{7cm}}
196 | - ocaml-lua: bindings to the Lua lib\\
197 | - schoca: implementation of the Scheme language\\
198 | \end{tabular}
199 |
200 | \section{Compression}
201 |
202 | \begin{tabular}{lp{7cm}}
203 | - CamlZIP: handling zip and gzip files\\
204 | \verb! http://forge.ocamlcore.org/projects/camlzip/!\\
205 | - CamlBZ2: bindings for the bzip2 lib\\
206 | \verb! http://camlbz2.forge.ocamlcore.org/!\\
207 | \end{tabular}
208 |
209 | \section{Cryptography}
210 |
211 | \begin{tabular}{lp{7cm}}
212 | - Cryptokit: cryptographic primitives\\
213 | \end{tabular}
214 |
215 | % TODO? rope
216 |
217 | \end{multicols}
218 | \end{document}
219 |
--------------------------------------------------------------------------------
/ocaml-opam/Makefile:
--------------------------------------------------------------------------------
1 |
2 | FILE=ocaml-opam
3 |
4 | all: $(FILE).pdf $(FILE)-bw.pdf
5 |
6 | %.pdf: %.tex ../common/ocaml-cs.cls
7 | pdflatex $*.tex
8 |
9 | $(FILE)-bw.tex: $(FILE).tex
10 | sed '1 s/colcode/nbcode/' $(FILE).tex > $(FILE)-bw.tex
11 |
12 | view: $(FILE).pdf
13 | evince $(FILE).pdf &
14 |
15 | edit:
16 | emacs $(FILE).tex &
17 |
18 | clean:
19 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
20 |
--------------------------------------------------------------------------------
/ocaml-opam/ocaml-opam-bw.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OCamlPro/ocaml-cheat-sheets/5b4fef2c0426680a2233ac2ec4fcf1a4d5fb55c5/ocaml-opam/ocaml-opam-bw.pdf
--------------------------------------------------------------------------------
/ocaml-opam/ocaml-opam.tex:
--------------------------------------------------------------------------------
1 | \documentclass[colcode]{../common/ocaml-cs}
2 |
3 | \lstset{language=opam}
4 |
5 | \makeheader{The \textbf{opam} package manager for OCaml (command-line)}{opam 2.0}{1}
6 | % warning: this is repeated for p.2
7 |
8 | \renewcommand{\arraystretch}{1.1}
9 | \begin{document}
10 |
11 |
12 | \begin{multicols}{3}
13 |
14 | \lst!opam command --help! \hfill show the manpage for \lst!command! \hfill \null
15 |
16 | Non-ambiguous prefixes are accepted \\
17 | (\emph{e.g.} {\lstset{morekeywords=[2]{inst}}\lst!opam inst . --deps!} for
18 | \lst!opam install . --deps-only!).
19 |
20 | \section{Installation}
21 | Download from: \hfill \url{https://opam.ocaml.org} \hfill \null
22 |
23 | \listvav{
24 | {\lst!opam init!} &
25 | {set up \opam, default repository, switch, scripts} \\
26 | \lst!opam init --bare! &
27 | {create \lst[language=neutral]!\~/.opam! without a compiler switch} \\
28 | \lst!opam init --reinit -i! &
29 | {reinstall opam scripts (\emph{e.g.} after upgrade)} \\
30 | }
31 |
32 | Run \lst[language=neutral]!eval $(opam env)! when changing switch or prompted, or accept the shell hook setup. %$
33 |
34 | \section{Configuration}
35 | \listvav{
36 | \lst!opam config report! & display a summary of the set-up \\
37 | \lst!opam command -v[v]! & print commands being run \\
38 | \lst!opam config set v val! & set switch variable \lst!v! \\
39 | \lst!opam config set-global v val! & set global config variable \lst!v! \\
40 | \lst!opam command --root root! & run opam using \lst!root! as opam root \\
41 | \lst!opam command --switch sw! & run opam on given \lst!sw! \\
42 | \lst!opam clean! & remove archive cache and artefacts \\
43 | }
44 |
45 | \section{Switches}
46 | \listvav{
47 | \splt{\lst!opam switch create [name] compiler!}
48 | {install a new prefix (``switch'') with the given \lst!compiler! and select
49 | it. \lst!compiler! should be one of \lst!ocaml-base-compiler[.version]!,
50 | \lst!ocaml-system[.version]!, \lst!ocaml-variants[.version]!, or \lst!--empty!.} \\
51 | \lst!opam switch! & list installed switches \\
52 | \lst!opam switch sw! & select the switch \lst!sw! \\
53 | \lst!opam switch create dir [compiler]! & install packages defined in \lst!dir! in a new local switch \\
54 | \lst!opam switch list-available! & list all available compilers \\
55 | \splt{\lst!opam exec [--switch sw] -- command args!}
56 | {run \lst!command args! in the correct environment} \\
57 | }
58 |
59 | The ``current switch'' is defined by the \lst!OPAMSWITCH! environment variable,
60 | the \lst!PWD! (for local switches), and the latest selected one.
61 |
62 | \section{Allowed URL formats}
63 | \listvav{
64 | \lst!http:// https:// ftp://! &
65 | remote archives \\
66 | \lst!ssh:// file://! & archives or directories \\
67 | \lst!path! & file paths (version control is detected) \\
68 | \lst!user@host:path! & ssh addresses (using {\em rsync})\\
69 | \lst!git:// hg:// darcs://! & version control \\
70 | \linecmd{\lst!git+ssh:// hg+https:// git+file://!}
71 | & version control with specific transport \\
72 | \linecmd{\lst!git+https://foo.com/git/bar\#branch!}
73 | & specific tag, branch, commit, etc. \\
74 | }
75 |
76 | \section{Packages}
77 | \listvav{
78 | \splt{\lst!opam install pkgs!}
79 | {\lst!pkgs! are package names, \lst!pkg.version!, constraints \lst!"pkg>=version"!} \\
80 | \lst!opam install --show! & only print a list of actions \\
81 | \lst!opam install --dry-run! & simulate everything \\
82 | \linecmd{\lst!opam install pkgs --best-effort!} & don't fail on impossible requests \\
83 | \lst!opam update [--all]! & update repositories and package sources \\
84 | \lst!opam upgrade [pkgs]! & bring installed packages to latest version\\
85 | \lst!opam remove pkgs! & uninstall packages \\
86 | \lst!opam remove --auto! & uninstall no longer needed dependencies \\
87 | \lst!opam reinstall pkgs! & recompile and reinstall packages \\
88 | \lst!opam source pkg [--dev]! & download package source \\
89 | % }
90 | % \listvav{
91 | \linecmd{\lst!opam reinstall --list-pending!} & show pending recompilations \\
92 | \linecmd{\lst!opam reinstall --forget-pending!} & at your own risk \\
93 | }
94 |
95 | \section{Exploring}
96 | \listvav{
97 | \lst!opam list! & list installed packages \\
98 | \lst!opam list --resolve pkg! &
99 | list a {\em sufficient} set of dependencies to install \lst!pkg! \\
100 | \lst!opam list [--rec] --required-by pkg! & list dependencies of \lst!pkg! \\
101 | \lst!opam list [--rec] --depends-on pkg! & list packages depending on \lst!pkg! \\
102 | \lst!opam list --roots! & exclude automatically-installed dependencies \\
103 | \lst!opam list --external pkg! & list external \lst!pkg! dependencies \\
104 | \lst!opam list --owns-file file! & find package owning \lst!file! \\
105 | \lst!opam show pkg [--field=flds]! & show package details \\
106 | \lst!opam show pkg --raw! & show package \opam file \\
107 | \lst!opam show pkg --list-files! & list all files belonging to \lst!pkg! \\
108 | \lst!opam var v! & print value of opam variable \\
109 | {\lstset{deletekeywords=[2]{list},morekeywords=[3]{list}}\lst!opam config list [pkg]!}
110 | & list variables [of package \lst!pkg!] \\
111 | }
112 |
113 | \section{Package pinning}
114 | \listvav{
115 | % \splt
116 | {\lst!opam install dir!} &
117 | {pin and install packages from the sources and definitions at \lst!dir!} \\
118 | \lst!opam pin pkg version! & pin \lst!pkg! to given version \\
119 | \lst!opam pin pkg[.version] url! & pin \lst!pkg!$^1$ to \lst!url! (can be a dir) and install \\
120 | \lst!opam pin url! & pin using package definitions at \lst!url! \\
121 | \lst!opam pin --dev pkg! & pin known package to its source repo \\
122 | \lst!opam pin [--short]! & list pinned packages \\
123 | {\lstset{deletekeywords=[2]{remove},morekeywords=[3]{remove}}\lst!opam pin remove pkgs|dir!}
124 | & unpin packages \\
125 | \lst!opam pin edit pkg! & tweak package definition \\
126 | }
127 |
128 | \lst!pin! commands also install/remove unless \lst!-n! is specified.
129 |
130 | $^1$If not using \lst!pkg.version!, version is defined by opam
131 | file, directory name, or latest known version.
132 |
133 | \section{Project development}
134 | \subsection{Working with local pins}
135 | \listvav{
136 | \splt{\lst!opam install pkg|dir --deps-only!}
137 | {just install all the pre-requisites} \\
138 | \splt{\lst!opam install pkg|dir --working-dir!}
139 | {bypass VCS, take all uncommitted changes} \\
140 | \splt{\lst!opam install pkg|dir --inplace-build!}
141 | {process build and install directly in the source} \\
142 | \splt{\lst!opam install pkg|dir --assume-built!}
143 | {directly run install commands from the source} \\
144 | \splt{\lst!opam lint pkg|dir|opamfile!}
145 | {check the style of a package definition} \\
146 | }
147 |
148 | \subsection{Sharing a dev setup}
149 | \listvav{
150 | \splt{\lst!opam lock pkg --direct-only!}
151 | {generate an \lst[language=neutral]!opam.locked! file with version-strict dependencies} \\
152 | \splt{\lst!opam lock pkg!}
153 | {generate an \lst[language=neutral]!opam.locked! file with a fixed dependency tree} \\
154 | \splt{\lst!opam install dir|pkg --locked!}
155 | {install, reproducing the same state as described by the \lst!locked! file} \\
156 | \splt{\lst!opam switch export|import file|-!}
157 | {switch state (compiler, installed packages, pins\ldots) save/restore}
158 | }
159 |
160 | \section{Configuring remotes}
161 | \listvav{
162 | \splt{\lst!opam repository [--all]!}
163 | {list defined repositories (current switch, or all)} \\
164 | \splt{\lst!opam switch create --repos default,custom=url ...!}
165 | {create a switch with repositories \lst!default!, and newly defined \lst!custom!} \\
166 | \splt{\lst!opam repository add name url --dont-select!}
167 | {define repository \lst!name! at \lst!url!} \\
168 | \splt{\lst!opam repository add name [url]!}
169 | {use \lst!name! in the current switch} \\
170 | \splt{\lst!opam repository add name [url] --set-default!}
171 | {use \lst!name! for newly created switches} \\
172 | \splt{\lst!opam repository add name [url] --all-switches!}
173 | {use \lst!name! for all existing switches} \\
174 | \splt{\lst!opam repository add name [url] --rank=-1!}
175 | {use \lst!name! with lowest priority} \\
176 | \splt{\lst!opam repository set-url name url!}
177 | {change repository url} \\
178 | \splt{\lst!opam repository set-repos foo,bar!}
179 | {redefine the repos selections for the current switch} \\
180 | }
181 |
182 | The definition for \lst!pkg.version! is taken from the highest ranking
183 | repository.
184 |
185 | %% \section{Upgrading opam}
186 | %% From binary: run script at
187 | %% {\scriptsize\url{https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh}}
188 |
189 | %% \ppar
190 | %% From source: \\
191 | %% \lst[language=shell]! opam install opam-devel! \\
192 | %% \lst[language=shell]! sudo cp $(opam var opam-devel:lib)/opam $(which opam)!\\
193 |
194 |
195 | \pagebreak
196 |
197 | \makeheader{The \textbf{opam} package manager for OCaml (packaging and tools)}{opam 2.0}{1}
198 |
199 |
200 | \section{Package definition files}
201 | \lstset{language=opam-file}
202 |
203 | Full specification:
204 | \hfill\url{http://opam.ocaml.org/doc/Manual.html#opam}\hfill\null
205 |
206 | \listvav{
207 | In source:&\lst!opam!, or \lst!pkg.opam!, or \lst!opam/pkg.opam! \\
208 | In a package repository:&
209 | {\lstset{deletekeywords=[5]version,morekeywords=[4]version}\lst!packages/pkg/pkg.version/opam!} \\
210 | }
211 |
212 | \begin{lstlisting}
213 | opam-version: "2.0"
214 | name: "project"
215 | version: "0.1"
216 | synopsis: "One-line description"
217 | description: """
218 | Longer description
219 | """
220 | maintainer: "Name "
221 | authors: ["Name "]
222 | license: "SPDX license" # see https://spdx.org/licenses/
223 | homepage: "https://project.org"
224 | bug-reports: "https://gitfoo.net/project/issues"
225 | dev-repo: "git+https://gitfoo.net/project.git"
226 | depends: ["ocaml"
227 | "ocamlfind" {<= "1.8"}
228 | "odoc" {with-doc & >= "1.0"}]
229 | # with a regular ./configure - make
230 | build: [["./configure" "--prefix=%{prefix}%"]
231 | [make]]
232 | install: [make "install"]
233 | # with dune (no 'install:' needed)
234 | depends: ["dune" {>= "1.10"}] # add to your other 'depends:'
235 | build: ["dune" "build" "-p" name "-j" jobs]
236 | \end{lstlisting}
237 |
238 | \columnbreak
239 | \section{Some optional fields}
240 | \listvav{
241 | \lst!tags: ["org:foo" "examples"]! & for package sorting \\
242 | \lst!depopts: [deps]! & optional dependencies \\
243 | \lst!substs: ["foo"]! & expand file \lst!"foo"! from \lst!"foo.in"! \\
244 | \linecmd{\lst!patches: ["f.patch" \{os = "macos"\}]!}
245 | & conditional patches \\
246 | \lst!run-test: [cmds]! & only when running with \lst!--with-test! \\
247 | \linecmd{\lst!pin-depends: [["pkg.version" "url"]]!}
248 | & when pinned, pin also these \\
249 | \lst!conflicts: [deps]! & anti-dependencies \\
250 | \lst!available: condition!& pre-requirements \\
251 | \lst!build-env: [CC = "foo"]!
252 | & custom build/install environment \\
253 | \linecmd{\lst!extra-source "fname" \{src: "url" checksum: "sha256=..."\}!}
254 | & additional downloads \\
255 | \linecmd{\lst!post-messages: """message""" \{condition\}!}
256 | & print to the user after install \\
257 | }
258 |
259 | When in a repository (not in-source):
260 | \smallskip
261 | \listvav{
262 | \lst!url \{! & \\
263 | \lst!\ \ src: "url"! & archive URL (or VCS, in custom repos) \\
264 | \lst!\ \ checksum: "sha512=XXX"! & supported: md5, sha256, sha512 \\
265 | \lst!\}! & \\
266 | }
267 |
268 | \columnbreak
269 | \section{Expressions}
270 | Variables are strings, booleans or undefined values.
271 |
272 | \listvav{
273 | postfix conditions & \lst![make "opt" \{condition\} "foo"] \{condition\}! \\
274 | dependencies & \lst@("p1" \{>= "0.5" \& != "0.7" \& condition\} | "p2")@ \\
275 | version ordering & \lst!"1.02"! $=$ \lst!"1.2"! $<$ \lst!"1.12"! $<$ \lst!"2.0\~"! $<$ \lst!"2.0"! \\
276 | comparisons & \lst!var = "value"!, \lst^var != ""^, \lst!"0.1" <= var! \\
277 | interpolation & \lst!"can be \%\{var\}\% or \%\{bool-var?foo:bar\}\%"! \\
278 | undefined & \lst!(?undef)! is \lst!false!, \lst!(undef | true)! is \lst!true!
279 | }
280 |
281 | \lst[alsoletter=]!_:var! is \lst[alsoletter=]!pkg:var! for the current package
282 |
283 | Some useful variables:
284 | \smallskip
285 | \listvav{
286 | \multicolumn{2}{l}{\textbf{Strings}} \\
287 | \lst!name!, \lst!version! & current package name, version \\
288 | & allowed \emph{e.g.} as \lst!depends: ["foo" \{= version\}]! \\
289 | \lst!lib! & this is \lst[language=neutral]!"\%\{prefix\}\%/lib"! \\
290 | \lst[alsoletter=]!pkg:lib! & this is \lst[language=neutral]!"\%\{prefix\}\%/pkg/lib"! \\
291 | \linecmd{\lst!arch!, \lst!os!, \lst!os-distribution!, \lst!os-family!, \lst!os-version!}
292 | & system detection \\
293 | \multicolumn{2}{l}{\textbf{Booleans}} \\
294 | \lst[alsoletter=]!pkg:dev! & \lst!pkg! was not built from a release archive \\
295 | \lst!with-test! & tests have been enabled (package-specific) \\
296 | \lst!with-doc! & documentation has been enabled (package-specific) \\
297 | \lst!build! & (only in depends) don't recompile when changed \\
298 | \lst!post! & (only in depends) not needed at build time \\
299 | }
300 |
301 | Run \lst[language=opam]!opam var! for more\\
302 |
303 |
304 | \end{multicols}
305 | \vfill
306 | \begin{multicols}{3}
307 | \section{External dependencies}
308 | \listvav{
309 | \lst!name: "conf-gtk3"! & by convention, use a "conf-" prefix \\
310 | \linecmd{\lst!depexts: ["libgtk-3-dev"] \{os-family = "debian"\}!}
311 | & define system package dependencies \\
312 | \lst!flags: conf!
313 | & package without install, for polling the system \\
314 | }
315 |
316 | Related commands:
317 | \smallskip
318 | \listvav{
319 | \lst[language=opam]!opam list -e --resolve pkg!
320 | & print requirements of \lst[language=opam]!pkg! on this system \\
321 | \lst[language=opam]!opam depext pkg!
322 | & handles requirements of \lst[language=opam]!pkg! (plugin) \\
323 | }
324 |
325 | \section{Publishing}
326 | Through Github pull-requests to the official repository at \\
327 | \dent\url{https://github.com/ocaml/opam-repository}
328 |
329 | Automatically, using the \lst!opam-publish! plugin:
330 | \smallskip
331 | \listvav{
332 | \lst[language=opam]!opam publish url!
333 | & publish from hosted source archive (plugin) \\
334 | \lst[language=opam]!opam publish [dir]! & publish latest tag from detected Github origin \\
335 | }
336 |
337 | \section{Repository administration}
338 | \lstset{language=opam}
339 | To be run from the root of an opam repository:
340 |
341 | {\lstset{keywords=[2]{admin},morekeywords=[3]{list,cache,lint}}
342 | \listvav{
343 | \lst!opam admin list! & list packages \\
344 | \lst!opam admin cache! & download all archives to cache \\
345 | \lst!opam admin index! & generate an index (needed for HTTP) \\
346 | \lst!opam admin lint! & lint all packages \\
347 | \lst!opam admin filter patterns! & only keep matching packages \\
348 | \splt{\lst!opam admin add-constraint "pkg<=3"!}
349 | {add a version constraint to all dependencies towards \lst!pkg!}
350 | }
351 | }
352 | %\pagebreak
353 |
354 | \end{multicols}
355 | \vfill
356 | \end{document}
357 |
--------------------------------------------------------------------------------
/ocaml-stdlib/Makefile:
--------------------------------------------------------------------------------
1 |
2 | ocaml-stdlib.pdf: ocaml-stdlib.tex
3 | pdflatex ocaml-stdlib.tex
4 |
5 | view: ocaml-stdlib.pdf
6 | evince ocaml-stdlib.pdf &
7 |
8 | clean:
9 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
10 |
--------------------------------------------------------------------------------
/ocaml-stdlib/ocaml-stdlib.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{../common/cheat-style}
3 |
4 | \begin{document}
5 |
6 | \setlength{\premulticols}{1pt}
7 | \setlength{\postmulticols}{1pt}
8 | \setlength{\multicolsep}{1pt}
9 | \setlength{\columnsep}{14pt}
10 |
11 | \makeheader{OCaml Standard Library}
12 |
13 | \begin{multicols}{3}
14 |
15 | \section{Standard Modules}
16 |
17 | \begin{itemize}
18 | \item \verb!Stdlib!: All basic functions
19 | \item Basic data types:
20 | \verb!Array!, \verb!Bool!, \verb!Bytes!, \verb!Char!, \verb!Float!, \verb!Fun!,
21 | \verb!Int!, \verb!Int32!, \verb!Int64!, \verb!List!, \verb!Nativeint!,
22 | \verb!Option!, \verb!Result!, \verb!String!, \verb!Unit!
23 | \item Advanced data types: \verb!Bigarray!, \verb!Buffer!, \verb!Complex!,
24 | \verb!Digest!, \verb!Hashtbl!, \verb!Lazy!, \verb!Map!, \verb!Queue!,
25 | \verb!Seq!, \verb!Set!, \verb!Stack!, \verb!Stream!, \verb!Uchar!
26 |
27 | \item System: \verb!Arg!, \verb!Filename!, \verb!Format!, \verb!Genlex!,
28 | \verb!Lexing!, \verb!Marshal!, \verb!Parsing!, \verb!Printexc!, \verb!Printf!,
29 | \verb!Random!, \verb!Scanf!, \verb!Sys!
30 | \item Tweaking: \verb!Callback!, \verb!Ephemeron!, \verb!Gc!, \verb!Oo!, \verb!Weak!
31 | \end{itemize}
32 |
33 | \section{Popular Functions per Module}
34 |
35 | \subsection{module List}
36 | \begin{Verbacorner}
37 | let l = {@vb{}List.init} 10 (fun i -> i)
38 | let len = {@vb{}List.length} l
39 | let acc' = {@vb{}List.fold@_left} (fun acc ele -> ...) acc l
40 | let acc' = {@vb{}List.fold@_right} (fun ele acc -> ...) l acc
41 | {@vb{}List.iter} (fun ele -> ... ) l;
42 | {@vb{}List.iteri} (fun index ele -> ... ) l;
43 | let l' = {@vb{}List.map}(fun ele -> ... ) l
44 | let l' = {@vb{}List.mapi}(fun index ele -> ... ) l
45 | let l' = {@vb{}List.filter@_map}(fun ele -> ... ) l
46 | let l' = {@vb{}List.rev} l1
47 | if {@vb{}List.mem} ele l then ...
48 | if {@vb{}List.for@_all} (fun ele -> ele >= 0) l then ...
49 | if {@vb{}List.exists} (fun ele -> ele < 0) l then ...
50 | let x = {@vb{}List.find} (fun x -> x < 0) ints
51 | let x_o = {@vb{}List.find@_opt} (fun x -> x < 0) ints
52 | let negs = {@vb{}List.find@_all} (fun x -> x < 0) ints
53 | let (negs,pos) = {@vb{}List.partition} (fun x -> x < 0) ints
54 | let ele = {@vb{}List.nth} list 2
55 | let head = {@vb{}List.hd} list
56 | let tail = {@vb{}List.tl} list
57 | let value = {@vb{}List.assoc} key assocs
58 | if {@vb{}List.mem@_assoc} key assocs then ...
59 | let assocs = {@vb{}List.combine} keys values
60 | let (keys, values) = {@vb{}List.split} assocs
61 | let l' = {@vb{}List.sort} String.compare l
62 | let l = {@vb{}List.append} l1 l2@ @emph{or} l1 @symbol{64} l2
63 | let list = {@vb{}List.concat} list_of_lists
64 | \end{Verbacorner}
65 |
66 | \begin{libcomments}
67 | \item Functions using physical equality: \verb!memq!, \verb!assq!,
68 | \verb!mem_assq!
69 | \item Non-tail recursive functions: \verb!append!, \verb!concat!, \verb!@!,
70 | \verb!map!, \verb!mapi!, \verb!fold_right!, \verb!map2!, \verb!fold_right2!,
71 | \verb!remove_assoc!, \verb!remove_assq!, \verb!split!, \verb!combine!,
72 | \verb!merge!
73 | \item Raising {\vb{}Not\_found}: \verb!find!, \verb!assoc!, \verb!assq!.
74 | \item Raising {\vb{}Failure}: \verb!hd!, \verb!tl!, \verb!nth!.
75 | \item Raising {\vb{}Invalid\_argument}: \verb!nth!, \verb!nth_opt!, \verb!init!,
76 | \verb!iter2!, \verb!map2!, \verb!rev_map2!, \verb!fold_left2!,
77 | \verb!fold_right2!, \verb!for_all2!, \verb!exists2!, \verb!combine!
78 | \end{libcomments}
79 |
80 | \columnbreak
81 |
82 | \subsection{module Hashtbl}
83 |
84 | \begin{Verbacorner}
85 | let t = {@vb{}Hashtbl.create} ~random:true 117
86 | {@vb{}Hashtbl.add} t key value;
87 | {@vb{}Hashtbl.replace} t key value;
88 | let value = {@vb{}Hashtbl.find} t key (* Not_found *)
89 | let value_o = {@vb{}Hashtbl.find@_opt} t key
90 | {@vb{}Hashtbl.iter} (fun key value -> ... ) t;
91 | let cond = {@vb{}Hashtbl.mem} t key
92 | {@vb{}Hashtbl.remove} t key;
93 | {@vb{}Hashtbl.clear} t;
94 | \end{Verbacorner}
95 |
96 |
97 | \subsection{module String}
98 | \begin{Verbacorner}
99 | let s = {@vb{}String.make} len char
100 | let len = {@vb{}String.length} s
101 | let char = s.[pos]
102 | let concat = prefix ^ suffix
103 | let s' = {@vb{}String.sub} s pos len'
104 | let s = {@vb{}String.concat} "," list_of_strings
105 | let p' = {@vb{}String.index@_from} s p char_to_find
106 | let p' = {@vb{}String.rindex@_from} s p char_to_find
107 | {@vb{}String.blit} src src_pos dst_bytes dst_pos len;
108 | let s' = {@vb{}String.uppercase@_ascii} s
109 | let s' = {@vb{}String.lowercase@_ascii} s
110 | let s' = {@vb{}String.escaped} s
111 | {@vb{}String.iter} (fun c -> ...) s;
112 | if {@vb{}String.contains} s char then ...
113 | let l = {@vb{}String.split@_on@_char} ',' s
114 | assert ("abc" = {@vb{}String.trim} " abc ");
115 | \end{Verbacorner}
116 |
117 | \begin{libcomments}
118 | \item Deprecated: \verb!set!, \verb!create!, \verb!copy!, \verb!fill!,
119 | \verb!uppercase!, \verb!lowercase!, \verb!capitalize!, \verb!uncapitalize!
120 | \item Raising {\vb{}Invalid\_argument}: \verb!get!, \verb!set!, \verb!create!,
121 | \verb!make!, \verb!init!, \verb!sub!, \verb!fill!, \verb!concat!,
122 | \verb!escaped!, \verb!index_from!, \verb!index_from_opt!, \verb!rindex_from!,
123 | \verb!rindex_from_opt!, \verb!contains_from!, \verb!rcontains_from!
124 | \item Raising {\vb{}Not\_found}: \verb!index!, \verb!rindex!, \verb!index_from!,
125 | \verb!rindex_from!
126 | \end{libcomments}
127 |
128 | \subsection{module Bytes}
129 | \begin{Verbacorner}
130 | let b = {@vb{}Bytes.create} length
131 | let b' = {@vb{}Bytes.make} length char
132 | let b' = {@vb{}Bytes.init} length (fun i -> ...)
133 | let b' = {@vb{}Bytes.copy} b
134 | let b' = {@vb{}Bytes.extend} b left right
135 | {@vb{}Bytes.blit} src srcoff dst dstoff len;
136 | let b = {@vb{}Bytes.concat} sep blist
137 | {@vb{}Bytes.iteri} (fun i c -> ...) b;
138 | let s = {@vb{}Bytes.unsafe@_to@_string} b
139 | let b = {@vb{}Bytes.unsafe@_of@_string} s
140 | let i = {@vb{}Bytes.get@_uint8} b index
141 | {@vb{}Bytes.set@_int32@_le} b pos 0l;
142 | (* Bytes.[sg]et_u?int(8|(16|32|64)_[lbn]e) *)
143 | \end{Verbacorner}
144 |
145 | \subsection{module Array}
146 | \begin{Verbacorner}
147 | let t = {@vb{}Array.make} len v
148 | let t = {@vb{}Array.init} len (fun pos -> v_at_pos)
149 | let v = t.(pos)
150 | t.(pos) <- v;
151 | let len = {@vb{}Array.length} t
152 | let t' = {@vb{}Array.sub} t pos len
153 | let t = {@vb{}Array.of@_list} list
154 | let list = {@vb{}Array.to@_list} t
155 | {@vb{}Array.iter} (fun v -> ... ) t;
156 | {@vb{}Array.iteri} (fun pos v -> ... ) t;
157 | let t' = {@vb{}Array.map} (fun v -> ... ) t
158 | let t' = {@vb{}Array.mapi} (fun pos v -> ... ) t
159 | let concat = {@vb{}Array.append} prefix suffix
160 | {@vb{}Array.sort} compare t;
161 | \end{Verbacorner}
162 |
163 | \subsection{modules Int, Int32, Int64, Nativeint}
164 | \begin{Verbacorner}
165 | module I = Int (* / Int32 / Int64 / Nativeint *)
166 | let x = {@vb{}I.add} {@vb{}I.zero} {@vb{}I.one}
167 | let y = {@vb{}I.mul} x ({@vb{}I.succ} x)
168 | let d,r = {@vb{}I.div} y x, {@vb{}I.rem} y x
169 | let x' = {@vb{}I.abs} ({@vb{}I.neg} {@vb{}I.minus@_one})
170 | let z = {@vb{}I.shift@_left} ({@vb{}I.logor} x y) 2
171 | let z' = {@vb{}I.shift@_right} z 2
172 | let z' = {@vb{}I.shift@_right@_logical} z 2
173 | (* unsigned operations not in Int *)
174 | let c : int = {@vb{}I.unsigned@_compare} {@vb{}I.max@_int} {@vb{}I.min@_int}
175 | let du, ru = {@vb{}I.unsigned@_div} y x, {@vb{}I.unsigned@_rem} y x
176 | \end{Verbacorner}
177 |
178 | \subsection{module Map}
179 |
180 | \begin{Verbacorner}
181 | module Dict = {@vb{}Map.Make}(String)
182 | module Dict = {@vb{}Map.Make}(struct
183 | type t = String.t
184 | let compare = String.compare
185 | end)
186 | let empty = {@vb{}Dict.empty}
187 | let dict = {@vb{}Dict.add} "x" value_x empty
188 | if {@vb{}Dict.mem} "x" dict then ...
189 | let value_x = {@vb{}Dict.find} "x" dict (* Not_found *)
190 | let value_x_o = {@vb{}Dict.find@_opt} "x" dict
191 | let new_dict = {@vb{}Dict.remove} "x" dict
192 | let dict' = {@vb{}Dict.update} "x"
193 | (function None -> ... | Some v -> ...) dict
194 | {@vb{}Dict.iter} (fun key value -> ..) dict;
195 | let new_dict = {@vb{}Dict.map} (fun value_x -> ..) dict
196 | let nee_dict = {@vb{}Dict.mapi} (fun key value -> ..) dict
197 | let acc = {@vb{}Dict.fold} (fun key value acc -> ..) dict acc
198 | if {@vb{}Dict.equal} String.equal dict other_dict then ...
199 | \end{Verbacorner}
200 |
201 | \pagebreak
202 |
203 | \subsection{module Set}
204 |
205 | \begin{Verbacorner}
206 | module S = {@vb{}Set.Make}(String)
207 | module S = {@vb{}Set.Make}(struct
208 | type t = String.t
209 | let compare = String.compare end)
210 | let empty = {@vb{}S.empty}
211 | let set = {@vb{}S.add} "x" empty
212 | if {@vb{}S.mem} "x" set then ...
213 | let new_set = {@vb{}S.remove} "x" set
214 | {@vb{}S.iter} (fun key -> ..) set;
215 | let union = {@vb{}S.union} set1 set2
216 | let intersection = {@vb{}S.inter} set1 set2
217 | let difference = {@vb{}S.diff} set1 set2
218 | let min = {@vb{}S.min@_elt} set
219 | let max = {@vb{}S.max@_elt} set
220 | \end{Verbacorner}
221 |
222 | \subsection{module Char}
223 |
224 | \begin{Verbacorner}
225 | let ascii_65 = {@vb{}Char.code} 'A'
226 | let char_A = {@vb{}Char.chr} 65
227 | let c' = {@vb{}Char.lowercase@_ascii} c
228 | let c' = {@vb{}Char.uppercase@_ascii} c
229 | let s = {@vb{}Char.escaped} c
230 | \end{Verbacorner}
231 |
232 | \subsection{module Buffer}
233 |
234 | \begin{Verbacorner}
235 | let b = {@vb{}Buffer.create} 10_000
236 | {@vb{}Printf.bprintf} b "Hello %s\n" name;
237 | {@vb{}Buffer.add@_string} b s;
238 | {@vb{}Buffer.add@_char} b '\n';
239 | {@vb{}Buffer.add@_utf@_8@_uchar} b uc;
240 | let s = {@vb{}Buffer.contents} b
241 | \end{Verbacorner}
242 |
243 |
244 |
245 |
246 | \subsection{module Digest}
247 | \begin{Verbacorner}
248 | let md5sum = {@vb{}Digest.string} str
249 | let md5sum = {@vb{}Digest.substring} str pos len
250 | let md5sum = {@vb{}Digest.file} filename
251 | let md5sum = {@vb{}Digest.channel} ic len
252 | let hexa = {@vb{}Digest.to@_hex} md5sum
253 | \end{Verbacorner}
254 |
255 |
256 |
257 | \subsection{module Filename}
258 |
259 | \begin{Verbacorner}
260 | if {@vb{}Filename.check@_suffix} name ".c" then ...
261 | let file = {@vb{}Filename.chop@_suffix} name ".c"
262 | let file_o = {@vb{}Filename.chop@_suffix@_opt} ~suffix:".c" name
263 | let file = {@vb{}Filename.basename} name
264 | let dir = {@vb{}Filename.dirname} name
265 | let name = {@vb{}Filename.concat} dir file
266 | if {@vb{}Filename.is@_relative} file then ...
267 | let file = {@vb{}Filename.temp@_file} prefix suffix
268 | let file = {@vb{}Filename.temp@_file} ~temp_dir:"." pref suf
269 | \end{Verbacorner}
270 |
271 | \columnbreak
272 |
273 | \subsection{module Seq}
274 |
275 | \begin{Verbacorner}
276 | let s = {@vb{}List.to_seq} l (* works with most containers *)
277 | let s = {@vb{}Array.to_seqi} a
278 | (* lazy functions *)
279 | let s = {@vb{}Seq.map} (fun e -> e) s
280 | let s = {@vb{}Seq.filter} (fun e -> true) s
281 | let s = {@vb{}Seq.filter_map} (fun e -> Some e) s
282 | let s = {@vb{}Seq.flat_map} (fun e -> {@vb{}Seq.return} e) s
283 | (* immediate functions *)
284 | let acc = {@vb{}Seq.fold_left} (fun acc e -> ...) acc s
285 | {@vb{}Seq.iter} (fun () -> ...) s;
286 | (* getting one value, (recalculating) *)
287 | let open Seq in
288 | match s () with
289 | | {@vb{}Nil} -> None
290 | | {@vb{}Cons} (e,s_tl) -> Some e
291 | \end{Verbacorner}
292 |
293 | \subsection{module Random}
294 |
295 | \begin{Verbacorner}
296 | {@vb{}Random.self@_init} ();
297 | {@vb{}Random.init} int_seed;
298 | let int_0_99 = {@vb{}Random.int} 100
299 | let coin = {@vb{}Random.bool} ()
300 | let float = {@vb{}Random.float} 1_000.
301 | \end{Verbacorner}
302 |
303 | \subsection{module Printexc}
304 |
305 | \begin{Verbacorner}
306 | (* $OCAMLRUNPARAM=b *)
307 | let s = {@vb{}Printexc.to@_string} exn
308 | let s = {@vb{}Printexc.get@_backtrace} ()
309 | {@vb{}Printexc.register@_printer} (function
310 | MyExn s -> Some (Printf.sprintf ...)
311 | | _ -> None);
312 | {@vb{}Printexc.set@_uncaught@_exception@_handler}
313 | (fun e raw_b -> () );
314 | try ... with e ->
315 | let b = {@vb{}Printexc.get@_raw@_backtrace} () in
316 | ...
317 | {@vb{}Printexc.raise@_with@_backtrace} e b
318 | \end{Verbacorner}
319 |
320 | % $ go home emacs you're drunk
321 |
322 | \subsection{module Ephemeron}
323 |
324 | \begin{Verbacorner}
325 | module E1 = {@vb{}Ephemeron.K1}
326 | let e = {@vb{}E1.create} ()
327 | {@vb{}E1.set@_key} e k;
328 | {@vb{}E1.set@_data} e d;
329 | {@vb{}E1.blit@_key} e_from e_to;
330 | if {@vb{}E1.check@_data} e then ...
331 | module EHASH = {@vb{}E1.Make} ( Hashable )
332 | \end{Verbacorner}
333 |
334 | \subsection{module Lazy}
335 |
336 | \begin{Verbacorner}
337 | let lazy_v = lazy (f x)
338 | let f_x = {@vb{}Lazy.force} lazy_v
339 | let f_x = match lazy_v with lazy f_x -> f_x
340 | \end{Verbacorner}
341 |
342 |
343 | \subsection{module Arg}
344 |
345 | \begin{Verbacorner}
346 | let arg_list = [
347 | "-do", {@vb{}Arg.Unit} (fun () -> ..), ": call with unit";
348 | "-n", {@vb{}Arg.Int} (fun int -> ..), " : with int";
349 | "-s", {@vb{}Arg.String} (fun s -> ..), " : with string";
350 | "-yes", {@vb{}Arg.Set} flag_ref, ": set ref";
351 | "-no", {@vb{}Arg.Clear} flag_ref, ": clear ref";
352 | ]
353 | let arg_usage = "prog [args] anons: run prog with args"
354 | {@vb{}Arg.parse} arg_list (fun anon -> ... ) arg_usage;
355 | {@vb{}Arg.parse@_dynamic}
356 | (ref arg_list) (fun anon -> ...) arg_usage;
357 | {@vb{}Arg.usage} arg_list arg_usage;
358 | let arg_list = {@vb{}Arg.align} arg_list
359 | \end{Verbacorner}
360 |
361 | \subsection{module Printf}
362 |
363 | \begin{Verbacorner}
364 | {@vb{}Printf.printf} "flush\n%!";
365 | let s = {@vb{}Printf.sprintf} "%s=%d or %x\n" string int hexa
366 | {@vb{}Printf.fprintf} oc "Error: %dL=%dl\n" int64 int32;
367 | {@vb{}Printf.bprintf} buf "%.3f if %b" float boolean;
368 | {@vb{}Printf.printf} "%a" (fun oc x -> ...) x;
369 | \end{Verbacorner}
370 |
371 | \subsection{module Format}
372 |
373 | \begin{topleft}
374 | Formatters:\\
375 | \begin{tabular}{lp{4cm}}
376 | \verb!@[ ...@]! & Horizontal box:\\
377 | & everything on one line\\
378 | \verb!@[ ...@]! & Vertical box:\\
379 | & next line at every break hint\\
380 | \verb!@[ ...@]! & Switch from horizontal box to vertical box if needed \\
381 | \verb!@[ ...@]! & Indented box\\
382 | \verb!@[ ...@]! & Fill line after line \\
383 | \verb!@[<... 5> ... @]! & Next line in box indented by 5 \\
384 | \verb!@!\textvisiblespace & Breakable space \\
385 | \verb!@,! & Break hint \\
386 | \verb!@;! & Full break \\
387 | \verb!@?! & Flush \\
388 | %\verb!@\n! & Newline \\
389 | \verb!@<4>%i! & Print int on 4 chars\\
390 | \verb!@.! & Close everything and flush \\
391 | \end{tabular}
392 | \end{topleft}
393 |
394 | \subsection{module Bigarray}
395 |
396 | \begin{Verbacorner}
397 | module B1 = {@vb{}Bigarray.Array1}
398 | let a = {@vb{}B1.create} {@vb{}Bigarray.char} {@vb{}Bigarray.c@_layout} length
399 | let e = {@vb{}B1.get} a i
400 | {@vb{}B1.set} a i e;
401 | {@vb{}B1.blit}
402 | ({@vb{}B1.sub@_left} src src_ofs len)
403 | ({@vb{}B1.sub@_left} dst dst_ofs len);
404 | \end{Verbacorner}
405 |
406 | \end{multicols}
407 | \end{document}
408 |
409 |
410 |
411 |
412 | % \subsection{module Queue}
413 |
414 | % \begin{Verbacorner}
415 | % \end{Verbacorner}
416 |
417 |
418 |
419 | % \subsection{module Stack}
420 | % \begin{Verbacorner}2 {@vb{}Stack.push}
421 | % 2 {@vb{}Stack.clear}
422 | % 1 {@vb{}Stack.pop}
423 | % 1 {@vb{}Stack.length}
424 | % 1 {@vb{}Stack.create}
425 | % \end{Verbacorner}
426 |
427 |
428 |
429 |
430 | % \subsection{module Stream}
431 |
432 | % \begin{Verbacorner}
433 | % \end{Verbacorner}
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 | % \subsection{module Genlex}
444 |
445 | % \begin{Verbacorner}
446 | % \end{Verbacorner}
447 |
448 |
449 |
450 |
451 |
452 | % \subsection{module Lexing}
453 |
454 | % \begin{Verbacorner}
455 | % 20 {@vb{}Lexing.lexeme}
456 | % 13 {@vb{}Lexing.lexeme@_char}
457 | % 3 {@vb{}Lexing.lexeme@_start}
458 | % 3 {@vb{}Lexing.engine}
459 | % 3 {@vb{}Lexing.dummy@_pos}
460 | % 2 {@vb{}Lexing.sub@_lexeme}
461 | % 2 {@vb{}Lexing.new@_engine}
462 | % 2 {@vb{}Lexing.lexeme@_end}
463 | % 2 {@vb{}Lexing.from@_channel}
464 | % 1 {@vb{}Lexing.sub@_lexeme@_opt}
465 | % \end{Verbacorner}
466 |
467 |
468 |
469 | % \subsection{module Parsing}
470 |
471 | % \begin{Verbacorner}
472 | % 819 {@vb{}Parsing.peek@_val}
473 | % 4 {@vb{}Parsing.yyparse}
474 | % 2 {@vb{}Parsing.symbol@_start@_pos}
475 | % 2 {@vb{}Parsing.symbol@_end@_pos}
476 | % 2 {@vb{}Parsing.is@_current@_lookahead}
477 | % 1 {@vb{}Parsing.rhs@_start@_pos}
478 | % 1 {@vb{}Parsing.rhs@_end@_pos}
479 | % 1 {@vb{}Parsing.parse@_error}
480 | % 1 {@vb{}Parsing.clear@_parser}
481 | % \end{Verbacorner}
482 |
483 |
484 |
485 |
486 |
487 | % \subsection{module Printf}
488 |
489 | % \begin{Verbacorner}
490 | % 32 {@vb{}Printf.fprintf}
491 | % 17 {@vb{}Printf.sprintf}
492 | % 2 {@vb{}Printf.eprintf}
493 | % 1 {@vb{}Printf.printf}
494 | % \end{Verbacorner}
495 |
496 |
497 |
498 | % \subsection{module Scanf}
499 |
500 | % \begin{Verbacorner}
501 | % \end{Verbacorner}
502 |
503 |
504 |
505 | % \subsection{module Sys}
506 |
507 | % \begin{Verbacorner}
508 | % 8 {@vb{}Sys.file@_exists}
509 | % 5 {@vb{}Sys.os@_type}
510 | % 4 {@vb{}Sys.getenv}
511 | % 2 {@vb{}Sys.command}
512 | % 1 {@vb{}Sys.remove}
513 | % 1 {@vb{}Sys.ocaml@_version}
514 | % 1 {@vb{}Sys.getcwd}
515 | % 1 {@vb{}Sys.executable@_name}
516 | % \end{Verbacorner}
517 |
518 |
519 |
520 |
521 |
522 | % \subsection{module Int32}
523 |
524 | % \begin{Verbacorner}
525 | % \end{Verbacorner}
526 |
527 |
528 |
529 | % \subsection{module Int64}
530 |
531 | % \begin{Verbacorner}
532 | % \end{Verbacorner}
533 |
534 |
535 |
536 | % \subsection{module Nativeint}
537 |
538 | % \begin{Verbacorner}
539 | % \end{Verbacorner}
540 |
541 |
542 |
543 |
544 | % \subsection{module Complex}
545 |
546 | % \begin{Verbacorner}
547 | % \end{Verbacorner}
548 |
549 |
550 |
551 | % \subsection{module Pervasives}
552 |
553 | % (in ocaml-lang.pdf ?)
554 |
555 | % \begin{Verbacorner}
556 | % \end{Verbacorner}
557 |
558 |
559 |
560 |
561 | % \end{multicols}
562 | % \end{document}
563 |
564 | %%% Local Variables:
565 | %%% mode: latex
566 | %%% TeX-master: t
567 | %%% End:
568 |
--------------------------------------------------------------------------------
/ocaml-tools/Makefile:
--------------------------------------------------------------------------------
1 |
2 | ocaml-tools.pdf: ocaml-tools.tex
3 | pdflatex ocaml-tools.tex
4 |
5 | view: ocaml-tools.pdf
6 | evince ocaml-tools.pdf &
7 |
8 | edit:
9 | emacs ocaml-tools.tex &
10 |
11 | clean:
12 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
13 |
--------------------------------------------------------------------------------
/ocaml-tools/ocaml-tools.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 | \usepackage{epsfig}
7 |
8 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
9 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
10 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
11 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
12 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
13 | }
14 | \pagestyle{empty}
15 | \makeatletter
16 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
17 | {-1ex plus -.5ex minus -.2ex}%
18 | {0.5ex plus .2ex}%x
19 | {\normalfont\large\bfseries}}
20 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
21 | {-1explus -.5ex minus -.2ex}%
22 | {0.5ex plus .2ex}%
23 | {\normalfont\normalsize\bfseries}}
24 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
25 | {-1ex plus -.5ex minus -.2ex}%
26 | {1ex plus .2ex}%
27 | {\normalfont\small\bfseries}}
28 | \makeatother
29 |
30 | % Define BibTeX command
31 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
32 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
33 |
34 | % Don't print section numbers
35 | \setcounter{secnumdepth}{0}
36 |
37 |
38 | \setlength{\parindent}{0pt}
39 | \setlength{\parskip}{0pt plus 0.5ex}
40 |
41 |
42 | % -----------------------------------------------------------------------
43 |
44 | \begin{document}
45 | \hspace{-2em}
46 | \begin{tabular}{l}
47 | \vspace{0cm}\epsfig{file=../licence/by-sa,width=24mm}\\
48 | \end{tabular}\vspace{-2mm}
49 | \hfill
50 | \hfill
51 | \Large{\textbf{OCaml Standard Tools}}
52 | \hfill
53 | \hfill
54 | \scriptsize
55 | OCaml v. 3.12.0 ---
56 | \today{} ---
57 | Copyright \copyright\ 2011 OCamlPro SAS
58 | ---
59 | {\bf http://www.ocamlpro.com/}\\
60 | \hrule~\\
61 | \raggedright
62 | \footnotesize
63 | \begin{multicols}{3}
64 |
65 | % multicol parameters
66 | % These lengths are set only within the two main columns
67 | %\setlength{\columnseprule}{0.25pt}
68 | \setlength{\premulticols}{1pt}
69 | \setlength{\postmulticols}{1pt}
70 | \setlength{\multicolsep}{1pt}
71 | \setlength{\columnsep}{2pt}
72 |
73 | \section{Standard Tools}
74 |
75 | \verb!.opt! tools are the same tools, compiled in native-code, thus
76 | much faster.
77 |
78 | \noindent\begin{tabular}{p{20mm}p{50mm}}
79 | \verb!ocamlopt![\verb!.opt!] & native-code compiler \\
80 | \verb!ocamlc![\verb!.opt!] & bytecode compiler \\
81 | \verb!ocaml! & interactive bytecode toplevel \\
82 | \verb!ocamllex![\verb!.opt!] & lexer compiler \\
83 | \verb!ocamlyacc! & parser compiler \\
84 | \verb!ocamldep![\verb!.opt!] & dependency analyser \\
85 | \verb!ocamldoc! & documentation generator \\
86 | \verb!ocamlrun! & bytecode interpreter \\
87 | \end{tabular}
88 |
89 | \section{Compiling}
90 |
91 | A unit interface must be compiled before its implementation. Here,
92 | \verb!ocamlopt! can replace \verb!ocamlc! anywhere to target asm.
93 |
94 | ~\hspace{-1em}\noindent
95 | \begin{tabular}{ll}
96 | \verb!ocamlc -c test.mli! & compile an interface \\
97 | \verb!ocamlc -c test.ml! & compile an implementation \\
98 | \verb!ocamlc -a -o lib.cma test.cmo! & generate a library \\
99 | \verb!ocamlc -o prog test.cmo! & generate an executable \\
100 | \multicolumn{2}{l}{
101 | {\tt ocamlopt -shared -o p.cmxs test.cmx}
102 | \hfill generate a plugin}\\
103 | \end{tabular}
104 |
105 | \subsection{Generic Arguments}
106 |
107 | \noindent\begin{tabular}{p{25mm}p{50mm}}
108 | \verb!-config! & print config and exit\\
109 | \verb!-c! & do not link \\
110 | \verb!-o!~\emph{target} & specify the target to generate\\
111 | \verb!-a! & build a library \\
112 | \verb!-pp!~\emph{prepro} & use a preprocessor (often \verb!camlp4!) \\
113 | \verb!-I!~\emph{directory} & search directory for dependencies \\
114 | \verb!-g! & add debugging info \\
115 | \verb!-annot! & generate source navigation information \\
116 | \verb!-i! & print inferred interface \\
117 | \verb!-thread! & generate thread-aware code\\
118 | \verb!-linkall! & link even unused units \\
119 | \verb!-nostdlib! & do not use installation directory \\
120 | \verb!-nopervasives! & do not autoload \verb!Pervasives! \\
121 | \end{tabular}
122 |
123 | \subsection{Linking with C}
124 |
125 | \noindent\begin{tabular}{p{25mm}p{50mm}}
126 | \verb!-cc!~\emph{gcc} & use as C compiler/linker\\
127 | \verb!-cclib!~\emph{option} & pass option to the C linker\\
128 | \verb!-ccopt!~\emph{option} & pass option to C compiler/linker \\
129 | \verb!-output-obj! & link, but output a C object file \\
130 | \verb!-noautolink! & do not automatically link C libraries\\
131 | \end{tabular}
132 |
133 | \subsection{Errors and Warnings}
134 |
135 | Warnings default is \verb!+a-4-6-7-9-27..29!
136 | \noindent\begin{tabular}{p{25mm}p{50mm}}
137 | \verb!-w!~\emph{wlist} & set or unset warnings\\
138 | \verb!-warn-errors!~\emph{wlist} & set or unset warnings as errors\\
139 | \verb!-warn-help! & print description of warnings\\
140 | \verb!-rectypes! & allow arbitrarily recursive types \\
141 | \end{tabular}
142 |
143 | \subsection{Native-code Specific Arguments}
144 |
145 | \noindent\begin{tabular}{p{20mm}p{50mm}}
146 | \verb!-p! & compile or link for profiling with \verb!gprof! \\
147 | \verb!-inline!~\emph{size} & set maximal function size for inlining \\
148 | \verb!-unsafe! & remove array bound checks \\
149 | \end{tabular}
150 |
151 | \subsection{Bytecode Specific Arguments}
152 |
153 | \noindent\begin{tabular}{p{30mm}p{50mm}}
154 | \verb!-custom! & link with runtime and C libraries \\
155 | \verb!-make-runtime! & generate a pre-customized runtime \\
156 | \verb!-use-runtime!~\emph{runtime} & use \emph{runtime} instead of \verb!ocamlrun! \\
157 | \end{tabular}
158 |
159 | \subsection{Packing Arguments}
160 |
161 | \noindent\begin{tabular}{p{30mm}p{45mm}}
162 | \verb!-pack -o!~\emph{file.cmo/.cmx} & pack several units in one unit \\
163 | \verb!-c -for-pack!~\emph{File} & compile unit to be packed into \emph{File} \\
164 | \end{tabular}
165 |
166 | \section{Interactive Toplevel}
167 | Use \verb!;;! to terminate and execute what you typed.\\
168 | Building your own: \verb!ocamlmktop -o unixtop unix.cma!\\
169 | \begin{tabular}{ll}
170 | \verb!#load "lib.cma";;! & load a compiled library/unit \\
171 | \verb!#use "file.ml";;! & compile and run a source file\\
172 | \verb!#directory "dir";;! & add directory to search path\\
173 | \verb!#trace!~\emph{function}\verb!;;! & trace calls to function \\
174 | \verb!#untrace!~\emph{function}\verb!;;! & stop tracing calls to function \\
175 | \verb!#quit;;! & quit the toplevel \\
176 | \end{tabular}
177 |
178 | \section{System Variables}
179 |
180 | \begin{tabular}{ll}
181 | \verb!OCAMLLIB! & Installation directory \\
182 | \verb!OCAMLRUNPARAM! & Runtime settings (e.g. \verb!b,s=256k,v=0x015!)\\
183 | \end{tabular}
184 | \begin{tabular}{l|llll}
185 | Flags & \verb!p! & ocamlyacc parser trace & \verb!b! & print backtrace \\
186 | & \verb!i! & major heap increment & \verb!s! & minor heap size \\
187 | & \verb!O! & compaction overhead & \verb!o! & space overhead \\
188 | & \verb!s! & stack size & \verb!h! & initial heap size \\
189 | & \verb!v! & GC verbosity \\
190 | \end{tabular}
191 |
192 | \section{Files Extensions}
193 | \begin{tabular}{p{5mm}p{21mm}|p{15mm}p{21mm}}
194 | \multicolumn{2}{c}{Sources} &\multicolumn{2}{c}{Objects}\\\hline
195 | .ml & implementation & .cmo & bytecode object \\
196 | & & .cmx + .o & asm object \\
197 | .mli & interface & .cmi & interface object \\
198 | .mly & parser & .cma & bytecode library \\
199 | .mll & lexer & .cmxa + .a & native library \\
200 | && .cmxs & native plugin \\
201 | \end{tabular}
202 |
203 | %\section{Interactive Toplevel}
204 | %
205 | %\section{Bytecode Interpreter}
206 |
207 | \section{Generating Documentation}
208 |
209 | \begin{tabular}{l}
210 | Generate documentation for source files:\\
211 | \verb!ocamldoc!~\emph{format}~\verb!-d!~\emph{directory}~\emph{sources.mli}\\
212 | where \emph{format} is:
213 | \noindent\begin{tabular}{|p{15mm}p{55mm}}
214 | \verb!-html! & Generate HTML \\
215 | \verb!-latex! & Generate LaTeX \\
216 | \verb!-texi! & Generate TeXinfo \\
217 | \verb!-man! & Generate man pages \\
218 | \end{tabular}
219 | \end{tabular}
220 |
221 | \vbox{
222 | ~\\
223 | {\large\bf Parsing} ~~~~~\verb!ocamlyacc grammar.mly!\\
224 | will generate \verb!grammar.mli! and \verb!grammar.ml! from the grammar specification.
225 |
226 | \noindent\begin{tabular}{p{5mm}p{65mm}}
227 | \verb!-v! & generates \verb!grammar.output! file with debugging info \\
228 | \end{tabular}
229 |
230 | \begin{tabular}{p{17mm}p{50mm}}
231 | \vspace{-2cm}
232 | \begin{verbatim}
233 | %{
234 | header
235 | %}
236 | declarations
237 | %%
238 | rules
239 | %%
240 | trailer
241 | \end{verbatim}
242 | &
243 | \begin{tabular}{p{45mm}}\hline
244 | \noindent Declarations:\\
245 | \begin{tabular}{ll}
246 | \verb!%token!~\emph{token} & \verb!%left!~\emph{symbol}\\
247 | \verb!%token !~\emph{token} & \verb!%right!~\emph{symbol}\\
248 | \verb!%start!~\emph{symbol} & \verb!%nonassoc!~\emph{symbol}\\
249 | \verb!%type !~\emph{symbol}\\
250 | \end{tabular}\\\hline
251 | Rules:\\
252 | \begin{tabular}{l}
253 | nonterminal \verb!:!\\
254 | \emph{symbol} ... \emph{symbol} \verb!{! \emph{action} \verb!}!\\
255 | \verb!|! ...\\
256 | \verb!|! \emph{symbol} ... \emph{symbol} \verb!{! \emph{action} \verb!} ;!\\
257 | \end{tabular}\\ \hline
258 | \end{tabular}
259 | \end{tabular}
260 |
261 | {\large\bf Lexing} ~~~~~\verb!ocamllex lexer.mll!\\
262 | will generate \verb!lexer.ml! from the lexer specification.
263 |
264 | \noindent\begin{tabular}{p{5mm}p{65mm}}
265 | \verb!-v! & generates \verb!lexer.output! file with debugging info \\
266 | \end{tabular}
267 |
268 | \hspace{-1em}\begin{tabular}{p{45mm}p{23mm}}
269 | \begin{tabular}{l}
270 | \{ header \}\\
271 | \verb!let! ident \verb!=! regexp ...\\
272 | \verb!rule! entrypoint \emph{args} \verb!=!\\
273 | ~~~\verb!parse! regexp \verb!{! \emph{action} \}\\
274 | ~~~~~~\verb!|! ...\\
275 | ~~~~~~\verb!|! regexp \verb!{! \emph{action} \verb!}!\\
276 | \verb!and! entrypoint \emph{args} \verb!=!\\
277 | ~~~\verb!parse! ...\\
278 | \verb!and! ...\\
279 | \verb!{! trailer \}\\
280 | \end{tabular} &
281 | \verb!Lexing.lexeme lexbuf! in \emph{action} to get the current
282 | token.
283 | \end{tabular}
284 |
285 |
286 | \section{Computing Dependencies}
287 |
288 | \verb!ocamldep! can be used to automatically compute dependencies. It
289 | takes in arguments all the source files (.ml and .mli), and some
290 | standard compiler arguments:
291 | \noindent\begin{tabular}{p{15mm}p{55mm}}
292 | \verb!-pp! \emph{prepro} & call a preprocessor \\
293 | \verb!-I! \emph{dir} & search directory for dependencies \\
294 | \verb!-modules! & print modules instead of Makefile format \\
295 | \verb!-slash! & use $\backslash{}$ instead of / \\
296 | \end{tabular}
297 |
298 | \section{Generic Makefile Rules}
299 |
300 | \begin{verbatim}
301 | .SUFFIXES: .mli .mll .mly .ml .cmo .cmi .cmx
302 | .ml.cmo :
303 | ocamlc -c $(OFLAGS) $(INCLUDES) $<
304 | .mli.cmi :
305 | ocamlc -c $(OFLAGS) $(INCLUDES) $<
306 | .ml.cmi :
307 | ocamlc -c $(OFLAGS) $(INCLUDES) $<
308 | .ml.cmx :
309 | ocamlopt -c $(OFLAGS) $(INCLUDES) $<
310 | .mll.ml :
311 | ocamllex $(OLEXFLAGS) $<
312 | .mly.ml :
313 | ocamlyacc $(OYACCFLAGS) $<
314 | .mly.mli:
315 | ocamlyacc $(OYACCFLAGS) $<
316 | \end{verbatim}
317 | }
318 |
319 | \end{multicols}
320 | \end{document}
321 |
322 |
323 | \section{Optional Warnings/Errors}
324 | For \verb!-w! and \verb!-warn-error!:
325 |
326 | \begin{tabular}{lp{7cm}}
327 | 1 & Suspicious-looking start-of-comment mark\\
328 | 2 & Suspicious-looking end-of-comment mark\\
329 | 3 & Deprecated syntax\\
330 | 4 & Matching remains complete even if type is extended\\
331 | 5 & Partially applied function\\
332 | 6 & Label omitted in function application\\
333 | 7 & Methods overridden in defining class\\
334 | 8 & Partial match: missing cases in pattern-matching\\
335 | 9 & Missing fields in a record pattern\\
336 | 10 & Non-unit first expr in sequence (\verb!-strict-sequence!)\\
337 | 11 & Redundant case in a pattern matching.\\
338 | 12 & Redundant sub-pattern in a pattern-matching.\\
339 | 13 & Override of an instance variable.\\
340 | 14 & Illegal backslash escape in a string constant.\\
341 | 15 & Private method made public implicitly.\\
342 | 16 & Unerasable optional argument.\\
343 | 17 & Undeclared virtual method.\\
344 | 18 & Non-principal type.\\
345 | 19 & Type without principality.\\
346 | 20 & Unused function argument.\\
347 | 21 & Non-returning statement.\\
348 | 22 & Camlp4 warning\\
349 | 23 & Useless record \verb!with! clause\\
350 | 24 & Invalid module name\\
351 | 25 & Pattern-matching exhaustiveness cannot be checked\\
352 | 26 & Unused variable not starting with \verb!_! in \verb!let! or \verb!as!\\
353 | 27 & Unused variable not starting with \verb!_! in arguments\\
354 | 28 & Constant variant with a wildcard pattern as argument\\
355 | 29 & Unescaped end-of-line in a string constant\\
356 | 30 & Same constructors defined in mutually recursive types\\
357 | \end{tabular}
358 |
359 | SRCS= x.mly y.mll z.ml
360 | TMP_SRCS= x.ml x.mli y.ml
361 | INCLUDES=-I library
362 | all: byte
363 | byte: prog.byte
364 | opt: prog.opt
365 | prog.byte: $(CMO_OBJS)
366 | ocamlc -o prog.byte library/lib.cma $(CMO_OBJS)
367 | prog.opt: $(CMX_OBJS)
368 | ocamlopt -o prog.opt library/lib.cmxa $(CMX_OBJS)
369 | clean:
370 | rm -f *.cm? *~ *.o *.a *.cmx?
371 | depend: $(TMP_SRCS)
372 | ocamldep $(INCLUDES) $(TMP_SRCS) $(SRCS) > .depend
373 | -include .depend
374 |
--------------------------------------------------------------------------------
/tuareg-mode/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #ocamlmode.pdf: ocamlmode.tex#
3 | # pdflatex ocamlmode.tex
4 |
5 | #view: ocamlmode.pdf
6 | # evince ocamlmode.pdf &
7 |
8 | tuareg-mode.pdf: tuareg-mode.tex
9 | pdflatex tuareg-mode.tex
10 |
11 | view: tuareg-mode.pdf
12 | evince tuareg-mode.pdf &
13 |
14 | edit:
15 | emacs tuareg-mode.tex &
16 |
17 | clean:
18 | rm -f *.bbl *.aux *.dvi *.ps *.log *~
19 |
--------------------------------------------------------------------------------
/tuareg-mode/ocamlmode.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 |
7 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
8 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
9 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
10 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
11 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
12 | }
13 | \pagestyle{empty}
14 | \makeatletter
15 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
16 | {-1ex plus -.5ex minus -.2ex}%
17 | {0.5ex plus .2ex}%x
18 | {\normalfont\large\bfseries}}
19 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
20 | {-1explus -.5ex minus -.2ex}%
21 | {0.5ex plus .2ex}%
22 | {\normalfont\normalsize\bfseries}}
23 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
24 | {-1ex plus -.5ex minus -.2ex}%
25 | {1ex plus .2ex}%
26 | {\normalfont\small\bfseries}}
27 | \makeatother
28 |
29 | % Define BibTeX command
30 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
31 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
32 |
33 | % Don't print section numbers
34 | \setcounter{secnumdepth}{0}
35 |
36 |
37 | \setlength{\parindent}{0pt}
38 | \setlength{\parskip}{0pt plus 0.5ex}
39 |
40 |
41 | % -----------------------------------------------------------------------
42 |
43 | \begin{document}
44 |
45 | \raggedright
46 | \footnotesize
47 | \begin{multicols}{3}
48 |
49 | % multicol parameters
50 | % These lengths are set only within the two main columns
51 | %\setlength{\columnseprule}{0.25pt}
52 | \setlength{\premulticols}{1pt}
53 | \setlength{\postmulticols}{1pt}
54 | \setlength{\multicolsep}{1pt}
55 | \setlength{\columnsep}{2pt}
56 |
57 | \begin{center}
58 | \Large{\textbf{OCaml Emacs Mode}} \\
59 | \end{center}
60 |
61 | \section{Short Cuts}
62 |
63 | \subsection{Subsection}
64 |
65 | \begin{tabular}{p{1cm}p{6cm}}
66 | \verb!C-c C-e! & Evaluate the phrase where the cursor is. \\
67 | \verb!C-c C-r! & Evaluate the whole selected region. \\
68 | \verb!C-c C-s! & Show the shell window, with ocaml running. \\
69 | \verb!C-c `! & Go to exact error location in the source. \\
70 | \verb!C-x C-x! & Switch between mark and cursor \\
71 | \end{tabular}
72 |
73 | \begin{tabular}{p{1cm}p{6cm}}
74 | \verb!TAB! & indent current line \\
75 | \verb!M-C-q! & indent phrase \\
76 | \verb!M-C-h! & mark phrase \\
77 | \verb!C-c C-a! & switch between interface and implementation \\
78 | \verb!C-c C-c! & compile (usually make) \\
79 | \verb!C-x `! & goto next error (also mouse button 2 in the compilation log) \\
80 | \end{tabular}
81 |
82 | \subsection{Use type information}
83 | You must have compiled your code with the \verb!-annot! option.
84 |
85 | \begin{tabular}{p{2cm}p{6cm}}
86 | \verb! C-c C-t! &caml-types-show-type\\
87 | \verb! C-c C-f! &caml-types-show-call\\
88 | \verb! C-c C-l! &caml-types-show-ident\\
89 | \verb! C-c mouse-1! &caml-types-explore\\
90 | \end{tabular}
91 |
92 | \subsection{Compiling}
93 | \begin{tabular}{p{2cm}p{6cm}}
94 | \verb! C-c C-c ! &compile\\
95 | \verb! C-c ` ! &caml-goto-phrase-error\\
96 | \end{tabular}
97 |
98 | \subsection{Inserting Forms}
99 | \begin{tabular}{p{2cm}p{6cm}}
100 | \verb!C-x C-x! & Switch between mark and cursor in forms \\
101 | \verb! C-c b ! &caml-insert-begin-form\\
102 | \verb! C-c f ! &caml-insert-for-form\\
103 | \verb! C-c i ! &caml-insert-if-form\\
104 | \verb! C-c l ! &caml-insert-let-form\\
105 | \verb! C-c m ! &caml-insert-match-form\\
106 | \verb! C-c t ! &caml-insert-try-form\\
107 | \verb! C-c w ! &caml-insert-while-form\\
108 | \end{tabular}
109 |
110 | \subsection{Miscellaneous}
111 | \begin{tabular}{p{2cm}p{6cm}}
112 | \verb! C-c i! &ocaml-add-path\\
113 | \verb! C-c ]! &ocaml-close-module\\
114 | \verb! C-c [! &ocaml-open-module\\
115 | \verb! C-c C-h! &caml-help\\
116 | \verb! C-c \t! &caml-complete\\
117 | \verb! C-c C-a ! &caml-find-alternate-file\\
118 | \verb! C-c C-e ! &caml-eval-phrase\\
119 | \verb! C-c C-[ ! &caml-backward-to-less-indent\\
120 | \verb! C-c C-] ! &caml-forward-to-less-indent\\
121 | \verb! C-c C-q ! &caml-indent-phrase\\
122 | \verb! C-c C-r ! &caml-eval-region\\
123 | \verb! C-c C-s ! &caml-show-subshell\\
124 | \verb! M-\ C-h ! &caml-mark-phrase\\
125 | \verb! M-\ C-q ! &caml-indent-phrase\\
126 | \verb! M-\ C-x ! &caml-eval-phrase\\
127 | \end{tabular}
128 |
129 |
130 |
131 |
132 | \subsection{Interactions with toplevel}
133 |
134 | Start the toplevel using M-x run-caml
135 |
136 |
137 | \begin{tabular}{p{1cm}p{6cm}}
138 | \verb!M-C-x! & send phrase to inferior caml process \\
139 | \verb!C-c C-r! & send region to inferior caml process \\
140 | \verb!C-c C-s! & show inferior caml process \\
141 | \verb!C-c `! & goto error in expression sent by M-C-x \\
142 | \end{tabular}
143 |
144 |
145 | \section{Sample \~{}/.emacs file}
146 | \begin{verbatim}
147 | (setq auto-mode-alist
148 | (cons '("\\.ml[iylp]?$" . caml-mode)
149 | auto-mode-alist))
150 | (autoload 'caml-mode "caml"
151 | "Major mode for editing Caml code." t)
152 | (autoload 'run-caml "inf-caml"
153 | "Run an inferior Caml process." t)
154 | (if window-system (require 'caml-font))
155 | (add-hook 'caml-mode-hook '(lambda ()
156 | (define-key caml-mode-map "\M-q" 'caml-indent-phrase)))
157 | \end{verbatim}
158 |
159 | \rule{0.3\linewidth}{0.25pt}
160 | \scriptsize
161 |
162 | Copyright \copyright\ 2011 OCamlPro SAS
163 |
164 | http://www.ocamlpro.com/
165 |
166 |
167 | \end{multicols}
168 | \end{document}
169 |
170 |
--------------------------------------------------------------------------------
/tuareg-mode/tuareg-mode.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,landscape]{article}
2 | \usepackage{multicol}
3 | \usepackage{calc}
4 | \usepackage{ifthen}
5 | \usepackage[landscape]{geometry}
6 | \usepackage{epsfig}
7 |
8 | \ifthenelse{\lengthtest { \paperwidth = 11in}}
9 | { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} }
10 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}}
11 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
12 | {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} }
13 | }
14 | \pagestyle{empty}
15 | \makeatletter
16 | \renewcommand{\section}{\@startsection{section}{1}{0mm}%
17 | {-1ex plus -.5ex minus -.2ex}%
18 | {0.5ex plus .2ex}%x
19 | {\normalfont\large\bfseries}}
20 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
21 | {-1explus -.5ex minus -.2ex}%
22 | {0.5ex plus .2ex}%
23 | {\normalfont\normalsize\bfseries}}
24 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
25 | {-1ex plus -.5ex minus -.2ex}%
26 | {1ex plus .2ex}%
27 | {\normalfont\small\bfseries}}
28 | \makeatother
29 |
30 | % Define BibTeX command
31 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
32 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
33 |
34 | % Don't print section numbers
35 | \setcounter{secnumdepth}{0}
36 |
37 |
38 | \setlength{\parindent}{0pt}
39 | \setlength{\parskip}{0pt plus 0.5ex}
40 |
41 |
42 | % -----------------------------------------------------------------------
43 |
44 | \begin{document}
45 |
46 | \hspace{-2em}
47 | \begin{tabular}{l}
48 | \vspace{0cm}\epsfig{file=../licence/by-sa,width=24mm}\\
49 | \end{tabular}\vspace{-2mm}
50 | \hfill
51 | \hfill
52 | \Large{\textbf{OCaml Emacs Mode (Tuareg)}}
53 | \hfill
54 | \hfill
55 | \scriptsize
56 | \today{} ---
57 | Copyright \copyright\ 2011 OCamlPro SAS
58 | ---
59 | http://www.ocamlpro.com/\\
60 | \hrule~\\
61 | \raggedright
62 | \footnotesize
63 | \vspace{-1em}
64 | \begin{multicols}{3}
65 |
66 | % multicol parameters
67 | % These lengths are set only within the two main columns
68 | %\setlength{\columnseprule}{0.25pt}
69 | \setlength{\premulticols}{1pt}
70 | \setlength{\postmulticols}{1pt}
71 | \setlength{\multicolsep}{1pt}
72 | \setlength{\columnsep}{2pt}
73 |
74 | \subsection{Generic Emacs Bindings}
75 |
76 | \begin{tabular}{ll}
77 | \verb!M-! & Meta modifier (usually Alt or Esc key)\\
78 | \verb!C-! & Control modifier\\
79 | \verb!S-! & Shift modifier\\
80 | \end{tabular}
81 |
82 | \begin{tabular}{p{15mm}p{55mm}}
83 | \verb!C-x C-c! & exit Emacs\\
84 | \verb!C-g! & abort current command\\
85 | \verb!M-x command! & call function \verb!command! \\
86 | \verb!C-h b! & describe all key bindings\\
87 | \end{tabular}
88 |
89 | \subsubsection{File Manipulation}
90 |
91 | \begin{tabular}{p{15mm}p{55mm}}
92 | \verb!C-x C-f! & open a new file\\
93 | \verb!C-x C-s! & save current file\\
94 | \verb!C-x b! & switch between opened files\\
95 | \verb!C-x b TAB! & list opened files and switch\\
96 | \verb!C-x k! & close current file \\
97 | \end{tabular}
98 |
99 |
100 | \subsubsection{Compiling}
101 | \noindent\begin{tabular}{p{15mm}p{55mm}}
102 | \verb!C-c C-c! & compile\\
103 | \verb!C-x `! & goto next error (also \verb!C-g p!)\\
104 | \verb!C-g p! & goto previous error\\
105 | \end{tabular}
106 |
107 | \subsubsection{Windows}
108 | \begin{tabular}{p{15mm}p{55mm}}
109 | \verb!C-x 5 f! & open file in new frame\\
110 | \verb!C-x 5 b! & switch to opened file in new frame\\
111 | \verb!C-x 5 0! & close current frame\\
112 | \verb!C-x 1! & unsplit current window (if split) \\
113 | \verb!C-x 2! & split window horizontally \\
114 | \verb!C-x 3! & split window vertically \\
115 | \verb!C-x o! & switch focus between split windows \\
116 | \end{tabular}
117 |
118 | \subsubsection{Navigation}
119 | \begin{tabular}{lp{55mm}}
120 | \verb!C-a! & go to beginning of line\\
121 | \verb!C-e! & go to end of line\\
122 | \verb!C-Home! & go to beginning of file\\
123 | \verb!C-End! & go to end of file\\
124 | \verb!C-Left! & go backward one word\\
125 | \verb!C-Right! & go forward one word\\
126 | \verb!C-Up! & go backward one paragraph\\
127 | \verb!C-Down! & go forward one paragraph\\
128 | \verb!M-g g! & goto line number\\
129 | \verb!M-x goto-char! & go to position \\
130 | \verb!C-l! & center window on current position\\
131 | \end{tabular}
132 |
133 |
134 | \subsubsection{Editing}
135 | \begin{tabular}{lp{55mm}}
136 | \verb!C-_! & undo last operation\\
137 | \verb!C-t! & permute two letters\\
138 | \verb!C-k! & cut end of line\\
139 | \verb!M-d! & cut end of word\\
140 | \verb!C-backspace! & cut beginning of word\\
141 | \verb!M-u! & end of word to uppercase\\
142 | \verb!M-l! & end of word to lowercase\\
143 | \verb!C-d! & delete current character\\
144 | \verb!C-!\emph{num}~\emph{letter} & print \emph{num} times \emph{letter}\\
145 | \end{tabular}
146 |
147 | \subsubsection{Search and Replace}
148 | \begin{tabular}{lp{55mm}}
149 | \verb!C-s! & incremental forward search \\
150 | \verb!C-r! & incremental backward search \\
151 | \verb!M-x replace-string! & replace string\\
152 | \verb!M-x replace-regexp! & replace regexp\\
153 | \verb!M-%! & query before replacing string\\
154 | \verb!C-M-%! & query before replacing regexp\\
155 | \end{tabular}
156 |
157 | \subsubsection{Selection (copy and paste)}
158 | \begin{tabular}{p{15mm}p{55mm}}
159 | \verb!C-Space! & start selecting text\\
160 | \verb!M-w! & copy selection \\
161 | \verb!C-w! & cut selection\\
162 | \verb!C-y! & paste selection\\
163 | \verb!M-y! & circulate between selections (after \verb!C-y!)\\
164 | \end{tabular}
165 |
166 | \subsection{Tuareg Key Bindings}
167 |
168 | \subsubsection{Using type information}
169 | You must have compiled your code with the \verb!-annot! option.
170 |
171 | \noindent\begin{tabular}{p{15mm}p{55mm}}
172 | \verb!C-mouse-2! & caml-types-explore\\
173 | \verb!C-c C-t! & caml-types-show-type\\
174 | \emph{unbound} & caml-types-show-ident\\
175 | \end{tabular}
176 |
177 | \subsubsection{Edting}
178 |
179 | \noindent\begin{tabular}{p{15mm}p{55mm}}
180 | \verb!C-c C-q! & tuareg-indent-phrase\\
181 | \verb!C-c home! & tuareg-move-inside-module-or-class-opening\\
182 | \verb!C-M-h! & tuareg-mark-phrase\\
183 | \verb!C-M-\! & indent-region\\
184 | \verb!C-x n d! & tuareg-narrow-to-phrase\\
185 | \end{tabular}
186 |
187 |
188 | \subsubsection{Interaction with the Toplevel}
189 |
190 | \noindent\begin{tabular}{p{15mm}p{55mm}}
191 | \verb!C-c C-s! & tuareg-run-caml\\
192 | \verb!C-x C-e! & tuareg-eval-phrase\\
193 | \verb!C-c C-e! & tuareg-eval-phrase\\
194 | \verb!C-M-x! & tuareg-eval-phrase\\
195 | \verb!C-c `! & tuareg-interactive-next-error-source\\
196 | \verb!C-c C-b! & tuareg-eval-buffer\\
197 | \verb!C-c C-r! & tuareg-eval-region\\
198 | \verb!C-c C-k! & tuareg-kill-caml\\
199 | \end{tabular}
200 |
201 |
202 | \subsubsection{Navigation}
203 | \noindent\begin{tabular}{p{15mm}p{55mm}}
204 | \verb!C-c C-a! & tuareg-find-alternate-file (switch between .ml/.mli files)\\
205 | \verb!C-c C-down! & tuareg-next-phrase\\
206 | \verb!C-M-down! & tuareg-next-phrase\\
207 | \verb!C-c C-n! & tuareg-next-phrase\\
208 | \verb!C-M-n! & tuareg-next-phrase\\
209 | \verb!C-M-p! & tuareg-previous-phrase\\
210 | \verb!C-c C-up! & tuareg-previous-phrase\\
211 | \verb!C-c C-p! & tuareg-previous-phrase\\
212 | \verb!C-M-up! & tuareg-previous-phrase\\
213 | \end{tabular}
214 |
215 | \vbox{
216 | \subsubsection{Help and Completion}
217 |
218 | \noindent\begin{tabular}{p{15mm}p{55mm}}
219 | \verb!C-c h! & caml-help\\
220 | \verb!C-c TAB! & tuareg-complete\\
221 | \verb!C-c [! & ocaml-open-module\\
222 | \verb!C-c ]! & ocaml-close-module\\
223 | \verb!C-c i! & ocaml-add-path\\
224 | \end{tabular}
225 |
226 | \subsubsection{Inserting Constructions}
227 |
228 | \noindent\begin{tabular}{p{15mm}p{55mm}}
229 | \verb!C-c . b! & tuareg-insert-begin-form\\
230 | \verb!C-c . c! & tuareg-insert-class-form\\
231 | \verb!C-c . f! & tuareg-insert-for-form\\
232 | \verb!C-c . i! & tuareg-insert-if-form\\
233 | \verb!C-c . l! & tuareg-insert-let-form\\
234 | \verb!C-c . m! & tuareg-insert-match-form\\
235 | \verb!C-c . t! & tuareg-insert-try-form\\
236 | \verb!C-c . w! & tuareg-insert-while-form\\
237 | \verb!C-x C-x! & Switch between mark and cursor \
238 | \end{tabular}
239 | }
240 |
241 | \vbox{
242 | \subsection{Emacs Configuration}
243 | \subsubsection{Sample \~{}/.emacs file}
244 | \begin{verbatim}
245 | (setq auto-mode-alist
246 | (cons '("\\.ml\\w?" . tuareg-mode)
247 | auto-mode-alist))
248 | (autoload 'tuareg-mode "tuareg"
249 | "Major mode for editing Caml code" t)
250 | (autoload 'camldebug "camldebug"
251 | "Run the Caml debugger" t)
252 | (if (and (boundp 'window-system) window-system)
253 | (when (string-match "XEmacs" emacs-version)
254 | (if (not (and (boundp 'mule-x-win-initted)
255 | mule-x-win-initted))
256 | (require 'sym-lock))
257 | (require 'font-lock)))
258 | (add-hook 'tuareg-mode-hook '(lambda ()
259 | (define-key tuareg-mode-map "\M-q"
260 | 'tuareg-indent-phrase)
261 | (define-key tuareg-mode-map "\C-c \C-i"
262 | 'caml-types-show-ident)
263 | (define-key tuareg-mode-map [f4] 'goto-line)
264 | (define-key tuareg-mode-map [f5] 'compile)
265 | (define-key tuareg-mode-map [f6] 'recompile)
266 | (define-key tuareg-mode-map [f7] 'next-error)
267 | (auto-fill-mode 1)
268 | (setq tuareg-sym-lock-keywords nil) ))
269 | (setq column-number-mode t)
270 | (setq mouse-wheel-follow-mouse t)
271 | (setq standard-indent 2)
272 | (transient-mark-mode 1)
273 | (setq visible-bell t)
274 | (setq show-paren-face 'modeline)
275 | (setq global-font-lock-mode t)
276 | (setq global-auto-revert-mode t)
277 | \end{verbatim}
278 | }
279 |
280 |
281 | \end{multicols}
282 | \end{document}
283 |
284 |
--------------------------------------------------------------------------------