\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{advitya} \pdfinfo{ /Title (ocaml.pdf) /Creator (Cheatography) /Author (advitya) /Subject (OCaml 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}{2C58A3} \definecolor{LightBackground}{HTML}{F1F4F9} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{advitya} via \textcolor{DarkBackground}{\uline{cheatography.com/20757/cs/3643/}}} \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}advitya \\ \uline{cheatography.com/advitya} \\ \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, 2015.\\ Updated 13th May, 2016.\\ 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{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{The Environment Model Semantics}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{env :: n || n \newline env :: e1 + e2 || n \newline if env :: e1 || n1 and env :: e2 || n2 \newline and n is the result of applying \newline primitive operation + to n1 and n2 \newline env :: (e1, e2) || (v1, v2) \newline if env :: e1 || v1 and env :: e2 || v2 \newline env :: fst e || v1 \newline if env :: e || (v1,v2) \newline env :: Left e || Left v \newline if env :: e || v \newline env :: match e with Left x -\textgreater{} e1 \newline | Right y -\textgreater{} e2 || v1 \newline if env :: e || Left v and \newline env+\{x=v\} :: e1 || v1 \newline env :: let x = e1 in e2 || v2 \newline if env :: e1 || v1 and \newline env+\{x=v1\} :: e2 || v2 \newline env :: (fun x -\textgreater{} e) || \textless{}\textless{}fun x -\textgreater{} e, env\textgreater{}\textgreater{} \newline env :: e1 e2 || v \newline if env :: e1 || \textless{}\textless{}fun x -\textgreater{} e, env'\textgreater{}\textgreater{} \newline and env :: e2 || v2 \newline and env' + \{x=v2\} :: e || v \newline env :: let rec f x = e1 in e2 || v \newline if env + \{f = \textless{}\textless{}f, fun x -\textgreater{} e1, env\textgreater{}\textgreater{}\} \newline :: e2 || v \newline env :: e1 e2 || v \newline if env :: e1 || \textless{}\textless{}f, fun x -\textgreater{} e, env'\textgreater{}\textgreater{} \newline and env :: e2 || v2 \newline and env' + \{x=v2,f=\textless{}\textless{}f, fun x -\textgreater{} e, env'\textgreater{}\textgreater{}\} \newline :: e || v} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Environment Model Semantics Rule with Lexical Scoping} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Technique to Generalize Folding}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{1. Write a recursive fold function that takes in one argument for each variant of the datatype. \newline 2. That fold function matches against the datatype variants, calling itself recursively on any instance of the datatype that it encounters. \newline 3. When a variant carries data of a type other than the datatype being folded, use the appropriate argument to fold to incorporate that data. \newline 4. When a variant carries no data, use the appropriate argument to fold to produce an accumulator. \newline \newline let rec fold\_left (f : 'a -\textgreater{} 'b -\textgreater{}'a) (acc : 'a) (lst : 'b list): 'a = \newline match lst with \newline {[}{]} -\textgreater{} acc \newline | x :: xs -\textgreater{} fold\_left f (f acc x) xs \newline \newline fold\_left : 'a -\textgreater{} 'b -\textgreater{} 'a -\textgreater{} 'a -\textgreater{} 'b list -\textgreater{} 'a \newline \newline let rec fold\_right (f : 'a -\textgreater{} 'b -\textgreater{} 'b) (l : 'a list) (acc : 'b) : 'b = \newline match l with \newline {[}{]} -\textgreater{} acc \newline | x :: xs -\textgreater{} f x (List.fold\_right f xs acc) \newline \newline fold\_right: 'a -\textgreater{} 'b -\textgreater{} 'b -\textgreater{} 'a list -\textgreater{} 'b -\textgreater{}'b \newline \newline Example of Generalized fold: \newline type \newline 'a exprTree = \newline | Val of 'a \newline | Unop of ('a -\textgreater{} 'a) {\emph{ 'a exprTree \newline | Binop of ('a -\textgreater{} 'a -\textgreater{} 'a) }} 'a exprTree * 'a exprTree \newline \newline let rec exprTree\_fold (foldVal) (foldUnop) (foldBinop) = function \newline | Val x -\textgreater{} foldVal x \newline | Unop (f, t) -\textgreater{} foldUnop f (exprTree\_fold foldVal foldUnop foldBinop t) | Binop (f, t1, t2) -\textgreater{} foldBinop f (exprTree\_fold foldVal foldUnop foldBinop t1) (exprTree\_fold foldVal foldUnop foldBinop t2) \newline ;;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Generalized fold and List folding functions} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function Type Inferrence}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Infer the type of functions from operations nested within the function. Start off by labeling all of the bindings and parameters with a random type Tn. And, then find out the type for each of them. Use patterns like the branches of an if and else statements are the same type and same goes for match statements. \newline % Row Count 7 (+ 7) Points to note are that the failure ("blah") and Exception Not\_found have type 'a (just something random), so they can be restricted to whatever the other type is in a match expression. Also, let rec f x= f x in f has type 'a -\textgreater{} 'b% Row Count 12 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Documenting Abstractions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A specification is a contract between an implementer of an abstraction and a client of an abstraction. An implementation satisfies a specification if it provides the described behavior. \newline % Row Count 4 (+ 4) Locality: abstraction can be understood without needing to examine implementation \newline % Row Count 6 (+ 2) Modifiability: abstraction can be reimplemented without changing implementation of other abstractions \newline % Row Count 9 (+ 3) Good Specs: \newline % Row Count 10 (+ 1) Sufficiently restrictive: rule out implementations that wouldn't be useful to clients \newline % Row Count 12 (+ 2) Sufficiently general: do not rule out implementations that would be useful to clients \newline % Row Count 14 (+ 2) Sufficiently clear: easy for clients to understand behavior \newline % Row Count 16 (+ 2) Abstraction function (AF) captures designer's intent in choosing a particular representation of a data abstraction. Not actually OCaml function but an abstract function. Maps concrete values to abstract values. Think about Set example, where implementer sees Set as 'a list {[}1;2{]} but user sees it as \{1,2\}. \newline % Row Count 23 (+ 7) Many-to-one: many values of concrete type can map to same value of abstract type. {[}1;2{]} \& {[}2;1{]} both map to \{1,2\} \newline % Row Count 26 (+ 3) Partial: some values of concrete type do not map to any value of abstract type \newline % Row Count 28 (+ 2) {[}1;1;2{]} because no duplicates \newline % Row Count 29 (+ 1) opA(AF(c)) = AF(opC(c)). AF commutes with op! \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Documenting Abstractions (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You might write: \newline % Row Count 1 (+ 1) – Abstraction Function: comment – AF: comment \newline % Row Count 3 (+ 2) – comment \newline % Row Count 4 (+ 1) Representation invariant characterizes which concrete values are valid and which are invalid. \newline % Row Count 6 (+ 2) -Valid concrete values will be mapped by AF to abstract values \newline % Row Count 8 (+ 2) -Invalid concrete value will not be mapped by AF to abstract values% Row Count 10 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Substitution Model of Evaluation}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{e1 + e2 -{}-\textgreater{} e1' + e2 \newline if e1 -{}-\textgreater{} e1' \newline v1 + e2 -{}-\textgreater{} v1 + e2' \newline if e2 -{}-\textgreater{} e2' \newline n1 + n2 -{}-\textgreater{} n3 \newline where n3 is the result of applying primitive operation + \newline to n1 and n2 \newline (e1, e2) -{}-\textgreater{} (e1', e2) \newline if e1 -{}-\textgreater{} e1' \newline (v1, e2) -{}-\textgreater{} (v1, e2') \newline if e2 -{}-\textgreater{} e2' \newline fst (v1,v2) -{}-\textgreater{} v1 \newline Left e -{}-\textgreater{} Left e' \newline if e -{}-\textgreater{} e' \newline match e with Left x -\textgreater{} e1 | Right y -\textgreater{} e2 \newline -{}-\textgreater{} match e' with Left x -\textgreater{} e1 | Right y -\textgreater{} e2 \newline if e -{}-\textgreater{} e' \newline match Left v with Left x -\textgreater{} e1 | Right y -\textgreater{} e2 \newline -{}-\textgreater{} e1\{v/x\} \newline match Right v with Left x -\textgreater{} e1 | Right y -\textgreater{} e2 \newline -{}-\textgreater{} e2\{v/y\} \newline let x = e1 in e2 -{}-\textgreater{} let x = e1' in e2 \newline if e1 -{}-\textgreater{} e1' \newline let x = v in e2 -{}-\textgreater{} e2\{v/x\} \newline e1 e2 -{}-\textgreater{} e1' e2 \newline if e1 -{}-\textgreater{} e1' \newline v e2 -{}-\textgreater{} v e2' \newline if e2 -{}-\textgreater{} e2' \newline \newline Capture Avoiding Substitution \newline \newline (fun x -\textgreater{} e) v2 -{}-\textgreater{} e\{v2/x\} \newline (Left e')\{e/x\} = Left e'\{e/x\} \newline (Right e')\{e/x\} = Right e'\{e/x\} \newline (match e' with Left y -\textgreater{} e1 | Right z -\textgreater{} e2)\{e/x\} \newline = match e'\{e/x\} with Left y -\textgreater{} e1\{e/x\} | Right z -\textgreater{} e2\{e/x\} \newline (match e' with Left x -\textgreater{} e1 | Right z -\textgreater{} e2)\{e/x\} \newline = match e'\{e/x\} with Left x -\textgreater{} e1 | Right z -\textgreater{} e2\{e/x\} \newline (match e' with Left y -\textgreater{} e1 | Right x -\textgreater{} e2)\{e/x\} \newline = match e'\{e/x\} with Left y -\textgreater{} e1\{e/x\} | Right x -\textgreater{} e2 \newline (match e' with Left x -\textgreater{} e1 | Right x -\textgreater{} e2)\{e/x\} \newline = match e'\{e/x\} with Left x -\textgreater{} e1 | Right x -\textgreater{} e2 \newline (let x = e1 in e2)\{v/x\} = let x = e1\{v/x\} in e2 \newline (let y = e1 in e2)\{v/x\} = let y = e1\{v/x\} in e2\{v/x\} \newline (e1,e2)\{e/x\} = (e1\{e/x\}, e2\{e/x\}) \newline (fst e')\{e/x\} = fst e'\{e/x\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Substitution Model Evaluation- Capture-avoiding substitution} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Example Module \& Functor example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Start off with this functor for Intervals. \newline module Make\_interval : \newline functor (Endpoint : Comparable) -\textgreater{} \newline sig \newline type t = Interval of Endpoint.t {\emph{ Endpoint.t | Empty \newline val create : Endpoint.t -\textgreater{} Endpoint.t -\textgreater{} t \newline val is\_empty : t -\textgreater{} bool \newline val contains : t -\textgreater{} Endpoint.t -\textgreater{} bool \newline val intersect : t -\textgreater{} t -\textgreater{} t \newline end \newline \newline Now, the functor does not have an abstract type. Because, the user can see the type in the functor. So, we have to hid that type t impelementation. There's a problem with Make\_interval. The invariant is enforced by the create function, but because Interval.t is not abstract, we can bypass the create function. So you do something like this with sharing constraints: : \newline \newline module Make\_interval(Endpoint : Comparable) : Interval\_intf with type endpoint = int struct \newline type endpoint = Endpoint.t \newline type t = | Interval of Endpoint.t }} Endpoint.t \newline | Empty} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Modules Signatures, Structures and Functors}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Basically, signature is the interface that we must follow for a certain module. The Structure of a module is the implementation of the given signature of the module. Furthermore, the functors go ahead and parameterize modules: that is, they will take in a module or multiple modules as inputs and return a new module that is parameterized with the input module. So, suppose you have a given Set module and you want this module to applicable to all types not only ints. So, you will need the notion of equality in your module, but this notion of equality is different between Ints and Strings, so you can parameterize by having a functor that has a type sig of EQUAL as its input. With functors remember to do the sharing constraints.% Row Count 15 (+ 15) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Matching Mechanics \& Type Declarations}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A type synonym is a new kind of declaration. The type and the name are interchangeable in every way. \newline % Row Count 3 (+ 3) Matching: Given a pattern p and a value v, decide \newline % Row Count 4 (+ 1) – Does pattern match value? \newline % Row Count 5 (+ 1) – If so, what variable bindings are introduced? \newline % Row Count 7 (+ 2) If p is a variable x, the match succeeds and x is bound to v. \newline % Row Count 9 (+ 2) If p is \_, the match succeeds and no bindings are introduced \newline % Row Count 11 (+ 2) If p is a constant c, the match succeeds if v is c. No bindings are introduced \newline % Row Count 13 (+ 2) If p is C p1, the match succeeds if v is C v1 (i.e., the same constructor) and p1 matches v1. The bindings are the bindings from the sub-match. \newline % Row Count 16 (+ 3) If p is (p1,..., pn) and v is (v1,..., vn), the match succeeds if p1 matches v1, and ..., and pn matches vn. The bindings are the union of all bindings from the sub-matches. \newline % Row Count 20 (+ 4) 1. If Expressions are just pattern matches \newline % Row Count 21 (+ 1) 2. Lists and options are just datatypes \newline % Row Count 22 (+ 1) 3. Let expressions are also pattern matches. \newline % Row Count 23 (+ 1) 4. A function argument can also be a pattern.% Row Count 24 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Type Checking Rules}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Syntax: \newline e1 + e2 \newline Type-checking: \newline If e1 and e2 have type int, then e1 + e2 has type int \newline Syntax: e1 \textless{} e2 \newline Type-checking: if e1 has type int and e2 has type \newline int then e1\textless{}e2 has type bool \newline Syntax: if e1 then e2 else e3 \newline Type-checking: if e1 has type bool and, for some type t, both e2 and e3 have type t, then if e1 then e2 else e3 has type t \newline Simplified syntax: \newline let x = e1 in e2 \newline Type-checking: \newline If e1:t1, and if e2:t2 under the assumption that \newline x:t1, then let x = e1 in e2 : t2 \newline Syntax: e0 (e1,...,en) \newline Type-checking: \newline If: e0 has some type (t1 {\emph{ ... }} tn) -\textgreater{} t \newline and e1 has type t1, ..., en has type tn \newline Then e0 (e1,...,en) has type t \newline Syntax: \{f1=e1;...;fn=en\} \newline Type-checking: \newline If e1:t1ande2:t2 and ... en:tn, and if t is a declared type of the form \{f1:t1, ..., fn:tn\} , then\{f1 = e1; ...; fn = en\}:t \newline Syntax: e.f \newline Type-checking: \newline If e:t1 and if t1 is a declared type of the form \{f:t2, ...\} , then e.f: t2 \newline None has type 'a option \newline – much like {[}{]} has type 'a list – None is a value \newline Some e :t option ife:t \newline – much like e::{[}{]} has type t list if e:t – If e-{}-\textgreater{}v then Some e-{}-\textgreater{}Some v \newline \newline Note- Datatype VS Records Table} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Type Checking Rules part of Semantics} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Key Points about Modules}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Other key points with modules: \newline % Row Count 1 (+ 1) 1. Difference between include and open is that include just sort of extends a module/ signature when its called. In general, opening a module adds the contents of that module to the environment that the compiler looks at to find the definition of various identifiers.While opening a module affects the environment used to search for identifiers, including a module is a way of actually adding new identifiers to a module proper. The difference between include and open is that we've done more than change how identifiers are searched for: we've changed what's in the module. Opening modules is usuallly not a good thing in top level as you are getting rid of the advantage of a new namespace and if you want to do it, do it locally. \newline % Row Count 16 (+ 15) 2. Don't expose the type of module especially in the signature, it is smart to hid from your user as they may abuse your invariant and don't have any idea on the implementation. So, you can also change the implementation without them knowing. \newline % Row Count 21 (+ 5) 3. We can also use sharing constraints in the context of a functor. The most common use case is where you want to expose that some of the types of the module being generated by the functor are related to the types in the module fed to the functor% Row Count 26 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4177 cm} p{0.4177 cm} x{1.42018 cm} x{1.92142 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Data Types VS Record VS Tuple}} \tn % Row 0 \SetRowColor{LightBackground} & \seqsplit{Declare} & \seqsplit{Build/Construct} & Access/ Destruct \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{DataType} & type & Constructor name & Pattern matching with match \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{Record} & type & Record expression with \{...\} & Pattern matching with let OR field selection with dot operator . \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} Tuple & N/A & Tuple expression with (...) & Pattern matching with let OR fst or snd \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{Records are used to store this AND that. Datatypes represent this OR that. Also, a tuple is just a record with its fields referred to by position, where as with records it is by name. \newline \newline Algebraic Dataypes of form \textless{}Datatype: Name Student\textgreater{} of String} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Dynamic VS Lexical Scoping}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Rule of dynamic scope: The body of a function is evaluated in the current dynamic environment at the time the function is called, not the old dynamic environment that existed at the time the function was defined. \newline % Row Count 5 (+ 5) Rule of lexical scope: The body of a function is evaluated in the old dynamic environment that existed at the time the function was defined, not the current environment when the function is called.% Row Count 9 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functions as First Class Citizens}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Functions are values \newline % Row Count 1 (+ 1) Can use them anywhere we use values \newline % Row Count 2 (+ 1) First-class citizens of language, afforded all the "rights" of any other values \newline % Row Count 4 (+ 2) – Functions can take functions as arguments – Functions can return functions as results \newline % Row Count 6 (+ 2) ...functions can be higher-order \newline % Row Count 7 (+ 1) Map: let rec map f xs = match xs with \newline % Row Count 8 (+ 1) {[}{]} -\textgreater{} {[}{]} \newline % Row Count 9 (+ 1) | x::xs' -\textgreater{} (f x)::(map f xs') \newline % Row Count 10 (+ 1) map: ('a-\textgreater{}'b)-\textgreater{}'alist-\textgreater{}'blist \newline % Row Count 11 (+ 1) Filter, Map, folds are iterators basically. They can iterate through structures just like normal loops can.% Row Count 14 (+ 3) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}