\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{benjenkinsv95} \pdfinfo{ /Title (ocaml-basics.pdf) /Creator (Cheatography) /Author (benjenkinsv95) /Subject (OCaml Basics Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{80D6D3} \definecolor{LightBackground}{HTML}{EFF9F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{OCaml Basics Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{benjenkinsv95} via \textcolor{DarkBackground}{\uline{cheatography.com/35376/cs/11125/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}benjenkinsv95 \\ \uline{cheatography.com/benjenkinsv95} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 9th March, 2017.\\ Updated 9th March, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Pervasives}} \tn % Row 0 \SetRowColor{LightBackground} val raise : exn -\textgreater{} 'a & Raise the given exception \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} val (=) : 'a -\textgreater{} 'a -\textgreater{} bool & tests for structural equality of e1 and e2 \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} val (\textless{}\textgreater{}) : 'a -\textgreater{} 'a -\textgreater{} bool & Negation of (=). \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} val (==) : 'a -\textgreater{} 'a -\textgreater{} bool & e1 == e2 tests for physical equality of e1 and e2. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} val (!=) : 'a -\textgreater{} 'a -\textgreater{} bool & Negation of (==). \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val (\textless{}) : 'a -\textgreater{} 'a -\textgreater{} bool} \tn % Row Count 13 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val (\textgreater{}) : 'a -\textgreater{} 'a -\textgreater{} bool} \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val (\textless{}=) : 'a -\textgreater{} 'a -\textgreater{} bool} \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val (\textgreater{}=) : 'a -\textgreater{} 'a -\textgreater{} bool} \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} val compare : 'a -\textgreater{} 'a -\textgreater{} int & compare x y returns 0 if x is equal to y, a negative integer if x is less than y, and a positive integer if x is greater than y. \tn % Row Count 23 (+ 7) % Row 10 \SetRowColor{LightBackground} val min : 'a -\textgreater{} 'a -\textgreater{} 'a & Return the smaller of the two arguments. \tn % Row Count 25 (+ 2) % Row 11 \SetRowColor{white} val max : 'a -\textgreater{} 'a -\textgreater{} 'a & Return the greater of the two arguments. \tn % Row Count 27 (+ 2) % Row 12 \SetRowColor{LightBackground} val not : bool -\textgreater{} bool & The boolean negation. \tn % Row Count 29 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val (\&\&) : bool -\textgreater{} bool -\textgreater{} bool} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Pervasives (cont)}} \tn % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val (||) : bool -\textgreater{} bool -\textgreater{} bool} \tn % Row Count 1 (+ 1) % Row 15 \SetRowColor{white} val (|\textgreater{}) : 'a -\textgreater{} ('a -\textgreater{} 'b) -\textgreater{} 'b & Reverse-application operator: x |\textgreater{} f |\textgreater{} g is exactly equivalent to g (f (x)). \tn % Row Count 5 (+ 4) % Row 16 \SetRowColor{LightBackground} val (\textasciitilde{}-) : int -\textgreater{} int & Unary negation. \tn % Row Count 7 (+ 2) % Row 17 \SetRowColor{white} val (mod) : int -\textgreater{} int -\textgreater{} int & Integer remainder. \tn % Row Count 9 (+ 2) % Row 18 \SetRowColor{LightBackground} val abs : int -\textgreater{} int & Return the absolute value of the argument. \tn % Row Count 12 (+ 3) % Row 19 \SetRowColor{white} val ( ** ) : float -\textgreater{} float -\textgreater{} float & Exponentiation. \tn % Row Count 14 (+ 2) % Row 20 \SetRowColor{LightBackground} val sqrt : float -\textgreater{} float & Square root. \tn % Row Count 16 (+ 2) % Row 21 \SetRowColor{white} val log : float -\textgreater{} float & Natural logarithm. \tn % Row Count 18 (+ 2) % Row 22 \SetRowColor{LightBackground} val log10 : float -\textgreater{} float & Base 10 logarithm. \tn % Row Count 20 (+ 2) % Row 23 \SetRowColor{white} val ceil : float -\textgreater{} float & Round above to an integer value. \tn % Row Count 22 (+ 2) % Row 24 \SetRowColor{LightBackground} val floor : float -\textgreater{} float & Round below to an integer value. \tn % Row Count 24 (+ 2) % Row 25 \SetRowColor{white} val abs\_float : float -\textgreater{} float & abs\_float f returns the absolute value of f. \tn % Row Count 27 (+ 3) % Row 26 \SetRowColor{LightBackground} val float\_of\_int : int -\textgreater{} float & Convert an integer to floating-point. \tn % Row Count 29 (+ 2) % Row 27 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val int\_of\_float : float -\textgreater{} int} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Pervasives (cont)}} \tn % Row 28 \SetRowColor{LightBackground} val (\textasciicircum{}) : string -\textgreater{} string -\textgreater{} string & String concatenation. \tn % Row Count 2 (+ 2) % Row 29 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val int\_of\_char : char -\textgreater{} int} \tn % Row Count 3 (+ 1) % Row 30 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val char\_of\_int : int -\textgreater{} char} \tn % Row Count 4 (+ 1) % Row 31 \SetRowColor{white} val fst : 'a * 'b -\textgreater{} 'a & Return the first component of a pair. \tn % Row Count 6 (+ 2) % Row 32 \SetRowColor{LightBackground} val snd : 'a * 'b -\textgreater{} 'b & Return the second component of a pair. \tn % Row Count 8 (+ 2) % Row 33 \SetRowColor{white} val (@) : 'a list -\textgreater{} 'a list -\textgreater{} 'a list & List concatenation. \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.8077 cm} x{8.4623 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Types and Type Inference}} \tn % Row 0 \SetRowColor{LightBackground} Function & Type \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} fun x y −\textgreater{} x + y & int -\textgreater{} int -\textgreater{} int \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Include variables that are passed in inside of the type.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.1169 cm} x{9.1531 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List basics}} \tn % Row 0 \SetRowColor{LightBackground} val length : 'a list -\textgreater{} int & Return the length \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} val nth : 'a list -\textgreater{} int -\textgreater{} 'a & Return the n-th element of the given list. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} val rev : 'a list -\textgreater{} 'a list & List reversal. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} val concat : 'a list list -\textgreater{} 'a list & Concatenate a list of lists. The elements of the argument are all concatenated together (in the same order) to give the result. \tn % Row Count 13 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List Iterators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val map : ('a -\textgreater{} 'b) -\textgreater{} 'a list -\textgreater{} 'b list} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} val mapi : (int -\textgreater{} 'a -\textgreater{} 'b) -\textgreater{} 'a list -\textgreater{} 'b list & Same as List.map, but the function is applied to the index of the element as first argument (counting from 0), and the element itself as second argument. \tn % Row Count 9 (+ 8) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val fold\_left : ('a -\textgreater{} 'b -\textgreater{} 'a) -\textgreater{} 'a -\textgreater{} 'b list -\textgreater{} 'a} \tn % Row Count 11 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val fold\_right : ('a -\textgreater{} 'b -\textgreater{} 'b) -\textgreater{} 'a list -\textgreater{} 'b -\textgreater{} 'b} \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val map2 : ('a -\textgreater{} 'b -\textgreater{} 'c) -\textgreater{} 'a list -\textgreater{} 'b list -\textgreater{} 'c list} \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val fold\_left2 : ('a -\textgreater{} 'b -\textgreater{} 'c -\textgreater{} 'a) -\textgreater{} 'a -\textgreater{} 'b list -\textgreater{} 'c list -\textgreater{} 'a} \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val fold\_right2 : ('a -\textgreater{} 'b -\textgreater{} 'c -\textgreater{} 'c) -\textgreater{} 'a list -\textgreater{} 'b list -\textgreater{} 'c -\textgreater{} 'c} \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List Scanning}} \tn % Row 0 \SetRowColor{LightBackground} val for\_all : ('a -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} bool & checks if all elements of the list satisfy the predicate p \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} val exists : ('a -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} bool & checks if at least one element of the list satisfies the predicate p \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val for\_all2 : ('a -\textgreater{} 'b -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} 'b list -\textgreater{} bool} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val exists2 : ('a -\textgreater{} 'b -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} 'b list -\textgreater{} bool} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} val mem : 'a -\textgreater{} 'a list -\textgreater{} bool & mem a l is true if and only if a is equal to an element of l. \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} val memq : 'a -\textgreater{} 'a list -\textgreater{} bool & Same as List.mem, but uses physical equality \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List Searching}} \tn % Row 0 \SetRowColor{LightBackground} val find : ('a -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} 'a & returns the first element of the list l that satisfies the predicate p \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} val filter : ('a -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} 'a list & returns all the elements of the list l that satisfy the predicate p \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} val partition : ('a -\textgreater{} bool) -\textgreater{} 'a list -\textgreater{} 'a list * 'a list & returns a pair of lists (l1, l2), where l1 is the list of all the elements of l that satisfy the predicate p, and l2 is the list of all the elements of l that do not satisfy p \tn % Row Count 17 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Lists of pairs}} \tn % Row 0 \SetRowColor{LightBackground} val split : ('a {\emph{ 'b) list -\textgreater{} 'a list }} 'b list & Transform a list of pairs into a pair of lists \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} val combine : 'a list -\textgreater{} 'b list -\textgreater{} ('a * 'b) list & Transform a pair of lists into a list of pairs \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{List Sorting}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val sort : ('a -\textgreater{} 'a -\textgreater{} int) -\textgreater{} 'a list -\textgreater{} 'a list} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} val merge : ('a -\textgreater{} 'a -\textgreater{} int) -\textgreater{} 'a list -\textgreater{} 'a list -\textgreater{} 'a list & Merge two lists: Assuming that l1 and l2 are sorted according to the comparison function cmp, merge cmp l1 l2 will return a sorted list containting all the elements of l1 and l2. \tn % Row Count 10 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `List.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{String basics}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val length : string -\textgreater{} int} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} val get : string -\textgreater{} int -\textgreater{} char & returns the character at index n \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} val make : int -\textgreater{} char -\textgreater{} string & String.make n c returns a fresh string of length n, filled with the character c. \tn % Row Count 7 (+ 4) % Row 3 \SetRowColor{white} val sub : string -\textgreater{} int -\textgreater{} int -\textgreater{} string & returns a fresh string of length len, containing the substring of s that starts at position start and has length len. \tn % Row Count 13 (+ 6) % Row 4 \SetRowColor{LightBackground} val concat : string -\textgreater{} string list -\textgreater{} string & String.concat sep sl concatenates the list of strings sl, inserting the separator string sep between each. \tn % Row Count 19 (+ 6) % Row 5 \SetRowColor{white} val map : (char -\textgreater{} char) -\textgreater{} string -\textgreater{} string & String.map f s applies function f in turn to all the characters of s (in increasing index order) and stores the results in a new string that is returned. \tn % Row Count 27 (+ 8) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{val trim : string -\textgreater{} string} \tn % Row Count 28 (+ 1) % Row 7 \SetRowColor{white} val index : string -\textgreater{} char -\textgreater{} int & returns the index of the first occurrence of character c in string s \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{String basics (cont)}} \tn % Row 8 \SetRowColor{LightBackground} val rindex : string -\textgreater{} char -\textgreater{} int & returns the index of the last occurrence of character c in string s \tn % Row Count 4 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{val contains : string -\textgreater{} char -\textgreater{} bool} \tn % Row Count 5 (+ 1) % Row 10 \SetRowColor{LightBackground} val uppercase\_ascii : string -\textgreater{} string & all lowercase letters translated to uppercase \tn % Row Count 8 (+ 3) % Row 11 \SetRowColor{white} val lowercase\_ascii : string -\textgreater{} string & all uppercase letters translated to lowercase \tn % Row Count 11 (+ 3) % Row 12 \SetRowColor{LightBackground} val capitalize\_ascii : string -\textgreater{} string & first character set to uppercase \tn % Row Count 13 (+ 2) % Row 13 \SetRowColor{white} val uncapitalize\_ascii : string -\textgreater{} string & first character set to lowercase \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Prefix with `String.`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Map}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{let rec map ( f : 'a -\textgreater{} 'b) (lst : 'a list) : 'b list = \newline match lst with \newline | {[}{]} -\textgreater{} {[}{]} \newline | hd :: tl -\textgreater{} f hd :: map f tl ;;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{fold\_left}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{let rec foldleft (f : 'a -\textgreater{} 'b -\textgreater{} 'a) \newline (acc : 'a) \newline (lst : 'b list) \newline : 'a = \newline match lst with \newline | {[}{]} -\textgreater{} acc \newline | hd :: tl -\textgreater{} foldleft f (f acc hd) tl ;;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.2053 cm} x{6.9167 cm} x{6.748 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Different Data Types}} \tn % Row 0 \SetRowColor{LightBackground} list & \textless{}type\textgreater{} list & Group together data of the same type \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} tuple & (\textless{}type1\textgreater{} ∗ \textless{}type2\textgreater{}) & Group together data of different types \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Record & \{field one: \textless{}type1\textgreater{}; field two: \textless{}type2\textgreater{};...\} & Groud together data of different types, but it is easier to access data. \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Algebraic} Data type & Name\_one of \textless{}type1\textgreater{} | Name\_two of \textless{}type2\textgreater{} & One piece of data can have many forms \tn % Row Count 14 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Module}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{module type Integer = \newline sig \newline val value : int \newline end \newline \newline module ThreeSig : Integer = \newline struct \newline let value = 3 \newline let is\_positive : bool = true \newline end \newline \newline Applying the signature Integer, via ": Integer" restricts ThreeSig makes only "value" public.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Functor}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Takes in a module and returns a new module. Ex. \newline \newline module Increment ( I : Integer ) : Integer = \newline struct \newline let value = I.value + 1 \newline end \newline \newline Functor can take in multiple modules.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Abstraction Barrier}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{If a signature has a type \newline \newline module type OPERATORS = \newline sig \newline type t \newline end ;; \newline \newline Then it can be overridden in the implementation using the "with" keyword \newline \newline module IntOps : OPERATORS with type t = int = \newline struct \newline type t = int \newline let times = ( ∗ ) \newline let divide = ( / ) \newline let plus = ( + ) \newline let int\_to\_t x = x \newline end ; ;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}