Changes in / [a3525c4:30a1f0c]
- Location:
- doc
- Files:
-
- 2 edited
-
LaTeXmacros/lstlang.sty (modified) (3 diffs)
-
theses/jiada_liang_MMath/relatedwork.tex (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/LaTeXmacros/lstlang.sty
ra3525c4 r30a1f0c 8 8 %% Created On : Sat May 13 16:34:42 2017 9 9 %% Last Modified By : Peter A. Buhr 10 %% Last Modified On : Sat Mar 9 17:03:58 202411 %% Update Count : 4 110 %% Last Modified On : Tue Mar 12 17:29:58 2024 11 %% Update Count : 42 12 12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 13 … … 99 99 } 100 100 101 \lstdefinelanguage{pseudo}{ 102 morekeywords={string,uint,int,bool,float}, 103 sensitive=true, 104 morecomment=[l]{//}, 105 morecomment=[s]{/*}{*/}, 106 morestring=[b]', 107 morestring=[b]", 108 morestring=[s]{`}{`}, 109 } 101 \lstdefinelanguage{OCaml}% 102 {morekeywords={ 103 and, as, asr, assert, begin, class, constraint do, done, downto, else, end, exception, external, 104 false, for, fun, function, functor, if, in, include, inherit, initializer, land, lazy, let, lor, lsl, lsr, lxor, 105 match, method, mod, module, open, mutable, new, nonrec, object, of, open, open!, or, private, rec, 106 sig, struct, then, to, true, try, type, val, virtual, when, while, with 107 }, 108 sensitive,% 109 morecomment=[n]{(*}{*)},% 110 morestring=[d]"% 111 }[keywords,comments,strings]% 110 112 111 113 % CFA programming language, based on ANSI C (with some gcc additions) … … 135 137 } 136 138 139 % pseudo code 140 \lstdefinelanguage{pseudo}{ 141 morekeywords={string,uint,int,bool,float}, 142 sensitive=true, 143 morecomment=[l]{//}, 144 morecomment=[s]{/*}{*/}, 145 morestring=[b]', 146 morestring=[b]", 147 morestring=[s]{`}{`}, 148 } 149 137 150 % Local Variables: % 138 151 % tab-width: 4 % -
doc/theses/jiada_liang_MMath/relatedwork.tex
ra3525c4 r30a1f0c 2463 2463 2464 2464 \section{OCaml} 2465 \lstnewenvironment{ocaml}[1][]{\lstset{language= ML,escapechar=\$,morekeywords={match},moredelim=**[is][\color{red}]{@}{@},}\lstset{#1}}{}2465 \lstnewenvironment{ocaml}[1][]{\lstset{language=OCaml,escapechar=\$,morekeywords={match},moredelim=**[is][\color{red}]{@}{@},}\lstset{#1}}{} 2466 2466 2467 2467 OCaml~\cite{Ocaml} provides a tagged variant (union) type, where multiple heterogeneously-typed objects share the same storage. … … 2469 2469 \begin{ocaml} 2470 2470 type weekday = Mon | Tue | Wed | Thu | Fri | Sat | Sun 2471 let day : weekday = Mon$\C{(* bind *)}$2471 let day : weekday @= Mon@ $\C{(* bind *)}$ 2472 2472 let take_class( d : weekday ) = 2473 matchd with $\C{(* matching *)}$2473 @match@ d with $\C{(* matching *)}$ 2474 2474 Mon | Wed -> Printf.printf "CS442\n" | 2475 2475 Tue | Thu -> Printf.printf "CS343\n" | … … 2487 2487 Each tag can have an associated heterogeneous type, with an n-ary constructor for creating a corresponding value. 2488 2488 \begin{ocaml} 2489 type colour = Red | Green of string | Blue of int * float2489 type colour = Red | Green of @string@ | Blue of @int * float@ 2490 2490 \end{ocaml} 2491 @colour@ is a summation of a nullary type, a unary product type of @string@, and a cross product of @int@ and @ bool@.2492 (Mathematically, a @Blue@ value is a Cartesian product of the @int@ type and the @bool@.)2491 @colour@ is a summation of a nullary type, a unary product type of @string@, and a cross product of @int@ and @float@. 2492 (Mathematically, a @Blue@ value is a Cartesian product of the types @int@ type and @float@.) 2493 2493 Hence, a variant type creates a sum of product of different types. 2494 2494 \begin{ocaml} 2495 let c : colour = Red $\C{(* 0-ary constructor*)}$2495 let c = Red $\C{(* 0-ary constructor, set tag *)}$ 2496 2496 let _ = match c with Red -> Printf.printf "Red, " 2497 let c : colour = Green( "abc" ) $\C{(* 1-ary constructor*)}$2497 let c = Green( "abc" ) $\C{(* 1-ary constructor, set tag *)}$ 2498 2498 let _ = match c with Green g -> Printf.printf "%s, " g 2499 let c : colour = Blue( 1, 1.5 ) $\C{(* 2-ary constructor*)}$2499 let c = Blue( 1, 1.5 ) $\C{(* 2-ary constructor, set tag *)}$ 2500 2500 let _ = match c with Blue( i, f ) -> Printf.printf "%d %g\n" i f 2501 2501 @Red, abc, 1 1.5@ … … 2504 2504 A variant type can have a recursive definition. 2505 2505 \begin{ocaml} 2506 type stringList = Empty | Pair of string * stringList2506 type @stringList@ = Empty | Pair of string * @stringList@ 2507 2507 \end{ocaml} 2508 2508 which is a recursive sum of product of types, called an \Newterm{algebraic data-type}. … … 2517 2517 Each recursion is counted to obtain the number of elements in the type. 2518 2518 2519 Note, the compiler statically guarantees that only the correct kind of type can be used in the \lstinline[language=ML]{match} statement.2520 However, the tag is dynamically set on binding (and possible reset on assignment), so the \lstinline[language=ML]{match} statement is effectively doing RTTI to select the matching case clause.2519 Note, the compiler statically guarantees that only the correct kind of type is used in the \lstinline[language=OCaml]{match} statement. 2520 However, the tag is dynamically set on binding (and possible reset on assignment), so a \lstinline[language=OCaml]{match} statement is effectively doing RTTI to select the matching case clause. 2521 2521 Hence, a tagged variant has no notion of enumerabilty, and therefore is not a real enumeration, except for the simple pure (untyped) case.
Note:
See TracChangeset
for help on using the changeset viewer.