Changeset 68a7028
- Timestamp:
- Sep 15, 2024, 2:35:13 PM (7 weeks ago)
- Branches:
- master
- Children:
- 4fa7096
- Parents:
- 0c88135
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
r0c88135 r68a7028 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 uses the same storage s as a C enumeration variablethat @posn@ can use as its underlying representation, and the label and value arrays take little storage.158 This semantics implies a \CFA enumeration variable uses the same storage 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
r0c88135 r68a7028 1320 1320 let day : week = Weekend Sun 1321 1321 \end{ocaml} 1322 The @week@ is a sum of @weekday@ and @weekend@; @week@ has all the enumeratorfrom 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: 1322 The type @week@ is the sum of @weekday@ and @weekend@, \ie @week@ has all the enumerators from the set @weekday@ and @weekend@. 1323 The sum type construction resembles containment inheritance from non-functional programming discipline, with the sum type being a wrapper class that contains one of its parent types. 1324 The wrapper is unwrapped with pattern matching: 1325 \begin{cquote} 1326 \begin{tabular}{@{}ll@{}} 1327 1327 \begin{ocaml} 1328 type weekday = Mon | Tue | Wed | Thu | Fri 1329 type weekend = Sat | Sun 1330 type week = Weekday of weekday | 1331 Weekend of weekend 1328 1332 let wd : weekday = Mon 1329 1333 let _ = match wd with 1330 Mon -> printf "Mon\n" | 1331 _ -> printf "Take a break\n" 1332 1334 Mon -> printf "Mon " | _ -> () 1333 1335 let we : weekend = Sun 1334 1336 let _ = match we with 1335 Sun -> printf "Sun\n" | 1336 _ -> printf "Take a break\n" 1337 1337 Sun -> printf "Sun " | _ -> () 1338 1338 let day : week = Weekend Sun 1339 1339 let _ = match day with 1340 Weekend Sun -> printf "Sun\n" |1341 _ -> printf "Take a break\n" 1340 Weekend Sun -> printf "Sun\n" | _ -> () 1341 1342 1342 \end{ocaml} 1343 & 1344 \begin{cfa} 1345 enum() weekday { Mon, Tue, Wed, Thu, Fri }; 1346 enum() weekend { Sat, Sun }; 1347 enum() week { inline weekday, inline weekend }; 1348 int main() { 1349 weekday wd = Mon; 1350 1351 printf( "%s ", label( wd ) ); 1352 weekend we = Sun; 1353 1354 printf( "%s ", label( we ) ); 1355 week day = Sun; 1356 1357 printf( "%s\n", label( day ) ); 1358 } 1359 \end{cfa} 1360 \\ 1361 \begin{cfa} 1362 Mon Sun Sun 1363 \end{cfa} 1364 \end{tabular} 1365 \end{cquote} 1343 1366 1344 1367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -
doc/theses/jiada_liang_MMath/test.ml
r0c88135 r68a7028 24 24 25 25 type week = Mon | Tue | Wed | Thu | Fri | Sat | Sun [@@deriving enumerate] 26 let _ = List.iter ( fun e -> printf "%d" (to_val e) ) all_of_week 26 (* let _ = List.iter ( fun e -> printf "%d" (to_val e) ) all_of_week*) 27 27 28 28 let day : week = Mon
Note: See TracChangeset
for help on using the changeset viewer.