Changeset 0c88135 for doc/theses/jiada_liang_MMath
- Timestamp:
- Sep 15, 2024, 12:25:59 PM (3 months ago)
- Branches:
- master
- Children:
- 68a7028
- Parents:
- 17fdf6f
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r17fdf6f r0c88135 145 145 \begin{cfa} 146 146 enum E { E1, E2, E3 }; 147 staticconst char * E_labels[3] = { "E1", "E2", "E3" };148 staticconst T E_values[3] = { t1, t2, t3 };147 const char * E_labels[3] = { "E1", "E2", "E3" }; 148 const T E_values[3] = { t1, t2, t3 }; 149 149 \end{cfa} 150 150 The generated C enumeration has enumerator values that match \CFA enumerator positions because of C's auto-initialization. … … 156 156 so these expressions remain unchanged by \CFA-cc. 157 157 Therefore, a \CFA enumeration variable has the same underlying representation as its generated C enumeration. 158 This semantics implies a \CFA enumeration variable does not use memory, that @posn@ can useits underlying representation, and the label and value arrays take little storage.158 This semantics implies a \CFA enumeration variable uses the same storages as a C enumeration variable that @posn@ can use as its underlying representation, and the label and value arrays take little storage. 159 159 It should be possible to eliminated the two arrays if unused, either by \CFA if local to a translation unit and unused, or by the linker if global but unreferenced. 160 160 Also, the label and value arrays are declared @static@ and initialized with constants, so the arrays are allocated in the @.data@ section and initialized before program execution. -
doc/theses/jiada_liang_MMath/relatedwork.tex
r17fdf6f r0c88135 1313 1313 PPX is beyond the scope of OCaml native language and it is a preprocessor directly modifying a parsed AST. In conclusion, there is no enumerating mechanism within the scope of OCaml language. 1314 1314 1315 \PAB{Why was this removed?} 1316 Enumeration subsetting is allowed but inheritance is restricted to classes not types. 1315 New types can be formed as a composition of existing types. 1317 1316 \begin{ocaml} 1318 1317 type weekday = Mon | Tue | Wed | Thu | Fri … … 1320 1319 type week = Weekday of weekday | Weekend of weekend 1321 1320 let day : week = Weekend Sun 1321 \end{ocaml} 1322 The @week@ is a sum of @weekday@ and @weekend@; @week@ has all the enumerator from the set @weekday@ and @weekend@. 1323 The sum type construction resembles containment inheritance from non-functional programming discipline, with 1324 the sum type being a wrapper class that contains one of its parent type. 1325 1326 The wrapper can be "unwrapped" with pattern matching: 1327 \begin{ocaml} 1328 let wd : weekday = Mon 1329 let _ = match wd with 1330 Mon -> printf "Mon\n" | 1331 _ -> printf "Take a break\n" 1332 1333 let we : weekend = Sun 1334 let _ = match we with 1335 Sun -> printf "Sun\n" | 1336 _ -> printf "Take a break\n" 1337 1338 let day : week = Weekend Sun 1339 let _ = match day with 1340 Weekend Sun -> printf "Sun\n" | 1341 _ -> printf "Take a break\n" 1322 1342 \end{ocaml} 1323 1343
Note: See TracChangeset
for help on using the changeset viewer.