Link Search Menu Expand Document
\( % cbs-katex.sty % \newcommand{\STYLE}[2]{\htmlClass{cbs-#1}{#2}} \newcommand{\DECL}[3]{\htmlId{#1:#2}{#3}} \newcommand{\REF}[3]{\href{###1:#2}{#3}} \newcommand{\HYPER}[5]{\href{#1/#2/index.html###3:#4}{#5}} % \SHADE{MATH} can be defined to produce a shaded background to highlight % inline MATH in running text: \newcommand{\SHADE}[1]{#1} % \KEY{TEXT}, \STRING{TEXT}, \ATOM{TEXT}, \LEX{TEXT} can be used in math mode: \newcommand{\KEY}[1]{\textsf{\textit{\STYLE{Key}{#1}}}} \newcommand{\STRING}[1]{\textsf{``\texttt{#1}''}} \newcommand{\ATOM}[1]{\textsf{`\texttt{#1}'}} \newcommand{\LEX}[1]{\textsf{\STYLE{Key}{`}\texttt{#1}\STYLE{Key}{'}}} % The following commands produce ASCII characters that are treated specially by LaTeX: \newcommand{\HASH}{\char`\#} \newcommand{\DOLLAR}{\char`\$} \newcommand{\PERCENT}{\char`\%} \newcommand{\AMPERSAND}{\char`\&} \newcommand{\APOSTROPHE}{\char`\'} \newcommand{\BACKSLASH}{\char`\\} \newcommand{\CARET}{\char`\^} \newcommand{\UNDERSCORE}{\char`\_} \newcommand{\GRAVE}{\char`\`} \newcommand{\LEFTBRACE}{\char`\{} \newcommand{\RIGHTBRACE}{\char`\}} \newcommand{\TILDE}{\textasciitilde} % {\char`\~} % \NAME{name} highlights the name; % \NAMEDECL{name} declares Name.name as the target of links to name; % \NAMEREF{name} links name to the target Name.name in the current file; % \NAMEHYPER{url}{file}{name} links name to Name.name at url/file/file.pdf. % Similarly for \VAR{partvariable}, \SYN{syntaxname}, \SEM{semanticsName}, % and \SECT{sectionnumber} % The kerns in \SUB and \VAR avoid overlaps with primes: \newcommand{\SUB}[1]{_{\kern-2mu\STYLE{PartVariable}{\textsf{#1}}}} % PLAIN \newcommand{\VAR}[1]{\STYLE{PartVariable}{\textsf{\textit{#1}\kern2mu}}} \newcommand{\NAME}[1]{\STYLE{Name}{\textsf{#1}}} \newcommand{\SYN}[1]{\STYLE{SyntaxName}{\textsf{#1}}} \newcommand{\SEM}[1]{\STYLE{SemanticsName}{\textsf{#1}}} \newcommand{\SECT}[1]{\STYLE{SectionNumber}{\textsf{#1}}} % DECL \newcommand{\VARDECL}[1]{\DECL{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEDECL}[1]{\DECL{Name}{#1}{\NAME{#1}}} \newcommand{\SYNDECL}[1]{\DECL{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMDECL}[1]{\DECL{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTDECL}[1]{\DECL{SectionNumber}{#1}{\textsf{#1}}} % REF \newcommand{\VARREF}[1]{\REF{PartVariable}{#1}{\VAR{#1}}} \newcommand{\NAMEREF}[1]{\REF{Name}{#1}{\NAME{#1}}} \newcommand{\SYNREF}[1]{\REF{SyntaxName}{#1}{\SYN{#1}}} \newcommand{\SEMREF}[1]{\REF{SemanticsName}{#1}{\SEM{#1}}} \newcommand{\SECTREF}[1]{\REF{SectionNumber}{#1}{\SECT{#1}}} % HYPER \newcommand{\VARHYPER}[3]{\HYPER{#1}{#2}{PartVariable}{#3}{\VAR{#3}}} \newcommand{\NAMEHYPER}[3]{\HYPER{#1}{#2}{Name}{#3}{\NAME{#3}}} \newcommand{\SYNHYPER}[3]{\HYPER{#1}{#2}{SyntaxName}{#3}{\SYN{#3}}} \newcommand{\SEMHYPER}[3]{\HYPER{#1}{#2}{SemanticsName}{#3}{\SEM{#3}}} \newcommand{\SECTHYPER}[3]{\HYPER{#1}{#2}{SectionNumber}{#3}{\SECT{#3}}} % \LEFTPHRASE MATH \RIGHTPHRASE produces [[ MATH ]] with proper brackets: \newcommand{\LEFTPHRASE}{\llbracket} \newcommand{\RIGHTPHRASE}{\rrbracket} % \LEFTGROUP MATH \RIGHTGROUP produces ( MATH ) where the parentheses are % highlighted the same as keywords: \newcommand{\LEFTGROUP}{\STYLE{Key}{(}} \newcommand{\RIGHTGROUP}{\STYLE{Key}{)}} % MATH\PLUS produces a superscript + % MATH\STAR produces a superscript * % MATH\QUERY produces a superscript ? \newcommand{\PLUS}{{}^{\texttt{+}}} \newcommand{\STAR}{{}^{\texttt{*}}} \newcommand{\QUERY}{{}^{\texttt{?}}} % \RULE{& PREMISE \\ & ...}{& FORMULA ... \\ & ...} produces an inference rule % with separately aligned premises and conclusion % PREMISE % ... % ----------- % FORMULA ... % ... \newcommand{\RULE}[2] {\frac{\begin{aligned}#1\end{aligned}}{\begin{aligned}#2\end{aligned}}} % \AXIOM{& FORMULA ... \\ & ...} produces an aligned formula % % FORMULA ... % ... \newcommand{\AXIOM}[1]{\begin{aligned}#1\end{aligned}} % \TO TYPE produces => TYPE \newcommand{\TO}{\mathop{\Rightarrow}} % TERM \TRANS TERM produces TERM ---> TERM \newcommand{\TRANS}{\longrightarrow} % TERM \xrightarrow{LABEL} TERM puts the label above the long arrow % \)

Languages-beta : OC-L-06-Patterns.cbs | PLAIN | PDF

OUTLINE

\[\KEY{Language} \quad \STRING{OCaml Light}\]

\(\SECT{6}\) Patterns

\[\begin{align*} \KEY{Syntax} \quad \VARDECL{P} : \SYNDECL{pattern} \ ::= \ & \ \SYNHYPER{../.}{OC-L-03-Names}{value-name} \\ \ \mid \ & \ \LEX{{\UNDERSCORE}} \\ \ \mid \ & \ \SYNHYPER{../.}{OC-L-05-Constants}{constant} \\ \ \mid \ & \ \SYNREF{pattern} \ \LEX{as} \ \SYNHYPER{../.}{OC-L-03-Names}{value-name} \\ \ \mid \ & \ \LEX{{(}} \ \SYNREF{pattern} \ \LEX{{)}} \\ \ \mid \ & \ \LEX{{(}} \ \SYNREF{pattern} \ \LEX{{:}} \ \SYNHYPER{../.}{OC-L-04-Type-Expressions}{typexpr} \ \LEX{{)}} \\ \ \mid \ & \ \SYNREF{pattern} \ \LEX{{|}} \ \SYNREF{pattern} \\ \ \mid \ & \ \SYNHYPER{../.}{OC-L-03-Names}{constr} \ \SYNREF{pattern} \\ \ \mid \ & \ \SYNREF{pattern} \ \SYNREF{comma-pattern}\PLUS \\ \ \mid \ & \ \LEX{{\LEFTBRACE}} \ \SYNHYPER{../.}{OC-L-03-Names}{field} \ \LEX{{=}} \ \SYNREF{pattern} \ \SYNREF{semic-field-pattern}\STAR \ \LEX{{;}}\QUERY \ \LEX{{\RIGHTBRACE}} \\ \ \mid \ & \ \LEX{{[}} \ \SYNREF{pattern} \ \SYNREF{semic-pattern}\STAR \ \LEX{{;}}\QUERY \ \LEX{{]}} \\ \ \mid \ & \ \SYNREF{pattern} \ \LEX{{:}{:}} \ \SYNREF{pattern} \\ \VARDECL{CP} : \SYNDECL{comma-pattern} \ ::= \ & \ \LEX{{,}} \ \SYNREF{pattern} \\ \VARDECL{SP} : \SYNDECL{semic-pattern} \ ::= \ & \ \LEX{{;}} \ \SYNREF{pattern} \\ \VARDECL{SFP} : \SYNDECL{semic-field-pattern} \ ::= \ & \ \LEX{{;}} \ \SYNHYPER{../.}{OC-L-03-Names}{field} \ \LEX{{=}} \ \SYNREF{pattern} \end{align*}\] \[\begin{align*} \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{(}} \ \VARREF{P} \ \LEX{{)}} \ \RIGHTPHRASE : \SYNREF{pattern} = \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{(}} \ \VARREF{P} \ \LEX{{:}} \ \VARHYPER{../.}{OC-L-04-Type-Expressions}{T} \ \LEX{{)}} \ \RIGHTPHRASE : \SYNREF{pattern} = \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{\LEFTBRACE}} \ \VARHYPER{../.}{OC-L-03-Names}{F} \ \LEX{{=}} \ \VARREF{P} \ \VARREF{SFP}\STAR \ \LEX{{;}} \ \LEX{{\RIGHTBRACE}} \ \RIGHTPHRASE : \SYNREF{pattern} = \LEFTPHRASE \ \LEX{{\LEFTBRACE}} \ \VAR{F} \ \LEX{{=}} \ \VAR{P} \ \VAR{SFP}\STAR \ \LEX{{\RIGHTBRACE}} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \LEFTPHRASE \ \LEX{{[}} \ \VARREF{P} \ \VARREF{SP}\STAR \ \LEX{{;}} \ \LEX{{]}} \ \RIGHTPHRASE : \SYNREF{pattern} = \LEFTPHRASE \ \LEX{{[}} \ \VAR{P} \ \VAR{SP}\STAR \ \LEX{{]}} \ \RIGHTPHRASE \end{align*}\]

Pattern evaluation

\[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{evaluate-pattern} \LEFTPHRASE \ \_ : \SYNREF{pattern} \ \RIGHTPHRASE : \TO \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{patterns} \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARHYPER{../.}{OC-L-03-Names}{VN} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern-bind} ( \SEMHYPER{../.}{OC-L-03-Names}{value-name} \LEFTPHRASE \ \VAR{VN} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \LEX{{\UNDERSCORE}} \ \RIGHTPHRASE = \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern-any} \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARHYPER{../.}{OC-L-05-Constants}{CNST} \ \RIGHTPHRASE = \SEMHYPER{../.}{OC-L-05-Constants}{value} \LEFTPHRASE \ \VAR{CNST} \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARREF{P} \ \LEX{as} \ \VARHYPER{../.}{OC-L-03-Names}{VN} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern-unite} ( \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE , \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern-bind} ( \SEMHYPER{../.}{OC-L-03-Names}{value-name} \LEFTPHRASE \ \VAR{VN} \ \RIGHTPHRASE ) ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARREF{P}\SUB{1} \ \LEX{{|}} \ \VARREF{P}\SUB{2} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern-else} ( \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \RIGHTPHRASE , \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{2} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARHYPER{../.}{OC-L-03-Names}{CSTR} \ \VARREF{P} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Variants}{variant} ( \SEMHYPER{../.}{OC-L-03-Names}{constr-name} \LEFTPHRASE \ \VAR{CSTR} \ \RIGHTPHRASE , \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARREF{P}\SUB{1} \ \LEX{{,}} \ \VARREF{P}\SUB{2} \ \VARREF{CP}\STAR \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Tuples}{tuple} ( \SEMREF{evaluate-comma-pattern-sequence} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \LEX{{,}} \ \VAR{P}\SUB{2} \ \VAR{CP}\STAR \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \LEX{{\LEFTBRACE}} \ \VARHYPER{../.}{OC-L-03-Names}{F} \ \LEX{{=}} \ \VARREF{P} \ \VARREF{SFP}\STAR \ \LEX{{\RIGHTBRACE}} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Generic}{closure} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{match-loosely} ( \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given}, \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Records}{record} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Maps}{map-unite} ( \SEMREF{evaluate-field-pattern-sequence} \LEFTPHRASE \ \VAR{F} \ \LEX{{=}} \ \VAR{P} \ \VAR{SFP}\STAR \ \RIGHTPHRASE ) ) ) ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \LEX{{[}} \ \VARREF{P} \ \VARREF{SP}\STAR \ \LEX{{]}} \ \RIGHTPHRASE = \\&\quad [ \SEMREF{evaluate-semic-pattern-sequence} \LEFTPHRASE \ \VAR{P} \ \VAR{SP}\STAR \ \RIGHTPHRASE ] \\ \KEY{Rule} \quad & \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VARREF{P}\SUB{1} \ \LEX{{:}{:}} \ \VARREF{P}\SUB{2} \ \RIGHTPHRASE = \\&\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{pattern} \ \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Generic}{closure} ( \\&\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Flowing}{if-true-else} ( \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values}{Value-Types}{is-equal} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given}, [ \ ] ), \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Abnormal}{Failing}{fail}, \\&\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{collateral} ( \\&\quad\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{match} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Lists}{head} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ), \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \RIGHTPHRASE ), \\&\quad\quad\quad\quad \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{match} ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Lists}{tail} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Giving}{given} ), \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{2} \ \RIGHTPHRASE ) ) ) ) \end{align*}\]

Pattern sequence evaluation

\[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{evaluate-comma-pattern-sequence} \LEFTPHRASE \ \_ : \LEFTGROUP \SYNREF{pattern} \ \SYNREF{comma-pattern}\STAR \RIGHTGROUP \ \RIGHTPHRASE \\&\quad : ( \TO \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{patterns} )\PLUS \\ \KEY{Rule} \quad & \SEMREF{evaluate-comma-pattern-sequence} \LEFTPHRASE \ \VARREF{P}\SUB{1} \ \LEX{{,}} \ \VARREF{P}\SUB{2} \ \VARREF{CP}\STAR \ \RIGHTPHRASE = \\&\quad \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \RIGHTPHRASE , \SEMREF{evaluate-comma-pattern-sequence} \LEFTPHRASE \ \VAR{P}\SUB{2} \ \VAR{CP}\STAR \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{evaluate-comma-pattern-sequence} \LEFTPHRASE \ \VARREF{P} \ \RIGHTPHRASE = \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{evaluate-semic-pattern-sequence} \LEFTPHRASE \ \_ : \LEFTGROUP \SYNREF{pattern} \ \SYNREF{semic-pattern}\STAR \RIGHTGROUP \ \RIGHTPHRASE \\&\quad : ( \TO \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{patterns} )\PLUS \\ \KEY{Rule} \quad & \SEMREF{evaluate-semic-pattern-sequence} \LEFTPHRASE \ \VARREF{P}\SUB{1} \ \LEX{{;}} \ \VARREF{P}\SUB{2} \ \VARREF{SP}\STAR \ \RIGHTPHRASE = \\&\quad \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \RIGHTPHRASE , \SEMREF{evaluate-semic-pattern-sequence} \LEFTPHRASE \ \VAR{P}\SUB{2} \ \VAR{SP}\STAR \ \RIGHTPHRASE \\ \KEY{Rule} \quad & \SEMREF{evaluate-semic-pattern-sequence} \LEFTPHRASE \ \VARREF{P} \ \RIGHTPHRASE = \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE \end{align*}\] \[\begin{align*} \KEY{Semantics} \quad & \SEMDECL{evaluate-field-pattern-sequence} \LEFTPHRASE \ \_ : \LEFTGROUP \SYNHYPER{../.}{OC-L-03-Names}{field} \ \LEX{{=}} \ \SYNREF{pattern} \ \SYNREF{semic-field-pattern}\STAR \RIGHTGROUP \ \RIGHTPHRASE \\&\quad : \TO ( \NAMEHYPER{../../../../../Funcons-beta/Values/Composite}{Maps}{maps} ( \NAMEHYPER{../../../../../Funcons-beta/Computations/Normal}{Binding}{ids}, \NAMEHYPER{../../../../../Funcons-beta/Values/Abstraction}{Patterns}{patterns} ) )\PLUS \\ \KEY{Rule} \quad & \SEMREF{evaluate-field-pattern-sequence} \LEFTPHRASE \ \VARHYPER{../.}{OC-L-03-Names}{F}\SUB{1} \ \LEX{{=}} \ \VARREF{P}\SUB{1} \ \LEX{{;}} \ \VARHYPER{../.}{OC-L-03-Names}{F}\SUB{2} \ \LEX{{=}} \ \VARREF{P}\SUB{2} \ \VARREF{SFP}\STAR \ \RIGHTPHRASE = \\&\quad ( \\&\quad \{ \SEMHYPER{../.}{OC-L-03-Names}{field-name} \LEFTPHRASE \ \VAR{F}\SUB{1} \ \RIGHTPHRASE \mapsto \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P}\SUB{1} \ \RIGHTPHRASE \}, \\&\quad \SEMREF{evaluate-field-pattern-sequence} \LEFTPHRASE \ \VAR{F}\SUB{2} \ \LEX{{=}} \ \VAR{P}\SUB{2} \ \VAR{SFP}\STAR \ \RIGHTPHRASE ) \\ \KEY{Rule} \quad & \SEMREF{evaluate-field-pattern-sequence} \LEFTPHRASE \ \VARHYPER{../.}{OC-L-03-Names}{F} \ \LEX{{=}} \ \VARREF{P} \ \RIGHTPHRASE = \\&\quad \{ \SEMHYPER{../.}{OC-L-03-Names}{field-name} \LEFTPHRASE \ \VAR{F} \ \RIGHTPHRASE \mapsto \SEMREF{evaluate-pattern} \LEFTPHRASE \ \VAR{P} \ \RIGHTPHRASE \} \end{align*}\]