Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / MLBasisAnnotationExamples
CommitLineData
7f918cf1
CE
1<!DOCTYPE html>\r
2<html lang="en">\r
3<head>\r
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5<meta name="generator" content="AsciiDoc 8.6.9">\r
6<title>MLBasisAnnotationExamples</title>\r
7<link rel="stylesheet" href="./asciidoc.css" type="text/css">\r
8<link rel="stylesheet" href="./pygments.css" type="text/css">\r
9\r
10\r
11<script type="text/javascript" src="./asciidoc.js"></script>\r
12<script type="text/javascript">\r
13/*<![CDATA[*/\r
14asciidoc.install();\r
15/*]]>*/\r
16</script>\r
17<link rel="stylesheet" href="./mlton.css" type="text/css">\r
18</head>\r
19<body class="article">\r
20<div id="banner">\r
21<div id="banner-home">\r
22<a href="./Home">MLton 20180207</a>\r
23</div>\r
24</div>\r
25<div id="header">\r
26<h1>MLBasisAnnotationExamples</h1>\r
27</div>\r
28<div id="content">\r
29<div id="preamble">\r
30<div class="sectionbody">\r
31<div class="paragraph"><p>Here are some example uses of <a href="MLBasisAnnotations">MLBasisAnnotations</a>.</p></div>\r
32</div>\r
33</div>\r
34<div class="sect1">\r
35<h2 id="_eliminate_spurious_warnings_in_automatically_generated_code">Eliminate spurious warnings in automatically generated code</h2>\r
36<div class="sectionbody">\r
37<div class="paragraph"><p>Programs that automatically generate source code can often produce\r
38nonexhaustive patterns, relying on invariants of the generated code to\r
39ensure that the pattern matchings never fail. A programmer may wish\r
40to elide the nonexhaustive warnings from this code, in order that\r
41legitimate warnings are not missed in a flurry of false positives. To\r
42do so, the programmer simply annotates the generated code with the\r
43<span class="monospaced">nonexhaustiveBind ignore</span> and <span class="monospaced">nonexhaustiveMatch ignore</span>\r
44annotations:</p></div>\r
45<div class="listingblock">\r
46<div class="content monospaced">\r
47<pre>local\r
48 $(GEN_ROOT)/gen-lib.mlb\r
49\r
50 ann\r
51 "nonexhaustiveBind ignore"\r
52 "nonexhaustiveMatch ignore"\r
53 in\r
54 foo.gen.sml\r
55 end\r
56in\r
57 signature FOO\r
58 structure Foo\r
59end</pre>\r
60</div></div>\r
61</div>\r
62</div>\r
63<div class="sect1">\r
64<h2 id="_deliver_a_library">Deliver a library</h2>\r
65<div class="sectionbody">\r
66<div class="paragraph"><p>Standard ML libraries can be delivered via <span class="monospaced">.mlb</span> files. Authors of\r
67such libraries should strive to be mindful of the ways in which\r
68programmers may choose to compile their programs. For example,\r
69although the defaults for <span class="monospaced">sequenceNonUnit</span> and <span class="monospaced">warnUnused</span> are\r
70<span class="monospaced">ignore</span> and <span class="monospaced">false</span>, periodically compiling with these annotations\r
71defaulted to <span class="monospaced">warn</span> and <span class="monospaced">true</span> can help uncover likely bugs. However,\r
72a programmer is unlikely to be interested in unused modules from an\r
73imported library, and the behavior of <span class="monospaced">sequenceNonUnit error</span> may be\r
74incompatible with some libraries. Hence, a library author may choose\r
75to deliver a library as follows:</p></div>\r
76<div class="listingblock">\r
77<div class="content monospaced">\r
78<pre>ann\r
79 "nonexhaustiveBind warn" "nonexhaustiveMatch warn"\r
80 "redundantBind warn" "redundantMatch warn"\r
81 "sequenceNonUnit warn"\r
82 "warnUnused true" "forceUsed"\r
83in\r
84 local\r
85 file1.sml\r
86 ...\r
87 filen.sml\r
88 in\r
89 functor F1\r
90 ...\r
91 signature S1\r
92 ...\r
93 structure SN\r
94 ...\r
95 end\r
96end</pre>\r
97</div></div>\r
98<div class="paragraph"><p>The annotations <span class="monospaced">nonexhaustiveBind warn</span>, <span class="monospaced">redundantBind warn</span>,\r
99<span class="monospaced">nonexhaustiveMatch warn</span>, <span class="monospaced">redundantMatch warn</span>, and <span class="monospaced">sequenceNonUnit\r
100warn</span> have the obvious effect on elaboration. The annotations\r
101<span class="monospaced">warnUnused true</span> and <span class="monospaced">forceUsed</span> work in conjunction&#8201;&#8212;&#8201;warning on\r
102any identifiers that do not contribute to the exported modules, and\r
103preventing warnings on exported modules that are not used in the\r
104remainder of the program. Many of the\r
105<a href="MLBasisAvailableLibraries">available libraries</a> are delivered with\r
106these annotations.</p></div>\r
107</div>\r
108</div>\r
109</div>\r
110<div id="footnotes"><hr></div>\r
111<div id="footer">\r
112<div id="footer-text">\r
113</div>\r
114<div id="footer-badges">\r
115</div>\r
116</div>\r
117</body>\r
118</html>\r