<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.23">
<title>MLBasisAnnotationExamples</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="./mlton.css">

</head>
<body class="article">
<div id="mlton-header">
<div id="mlton-header-text">
<h2>
<a href="./Home">
MLton
20241230
</a>
</h2>
</div>
</div>
<div id="header">
<h1>MLBasisAnnotationExamples</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Here are some example uses of <a href="MLBasisAnnotations">MLBasisAnnotations</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_eliminate_spurious_warnings_in_automatically_generated_code">Eliminate spurious warnings in automatically generated code</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Programs that automatically generate source code can often produce
nonexhaustive patterns, relying on invariants of the generated code to
ensure that the pattern matchings never fail.  A programmer may wish
to elide the nonexhaustive warnings from this code, in order that
legitimate warnings are not missed in a flurry of false positives.  To
do so, the programmer simply annotates the generated code with the
<code>nonexhaustiveBind ignore</code> and <code>nonexhaustiveMatch ignore</code>
annotations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>local
  $(GEN_ROOT)/gen-lib.mlb

  ann
    "nonexhaustiveBind ignore"
    "nonexhaustiveMatch ignore"
  in
    foo.gen.sml
  end
in
  signature FOO
  structure Foo
end</pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_deliver_a_library">Deliver a library</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Standard ML libraries can be delivered via <code>.mlb</code> files.  Authors of
such libraries should strive to be mindful of the ways in which
programmers may choose to compile their programs.  For example,
although the defaults for <code>sequenceNonUnit</code> and <code>warnUnused</code> are
<code>ignore</code> and <code>false</code>, periodically compiling with these annotations
defaulted to <code>warn</code> and <code>true</code> can help uncover likely bugs.  However,
a programmer is unlikely to be interested in unused modules from an
imported library, and the behavior of <code>sequenceNonUnit error</code> may be
incompatible with some libraries.  Hence, a library author may choose
to deliver a library as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>ann
  "nonexhaustiveBind warn" "nonexhaustiveMatch warn"
  "redundantBind warn" "redundantMatch warn"
  "sequenceNonUnit warn"
  "warnUnused true" "forceUsed"
in
  local
    file1.sml
    ...
    filen.sml
  in
    functor F1
    ...
    signature S1
    ...
    structure SN
    ...
  end
end</pre>
</div>
</div>
<div class="paragraph">
<p>The annotations <code>nonexhaustiveBind warn</code>, <code>redundantBind warn</code>,
<code>nonexhaustiveMatch warn</code>, <code>redundantMatch warn</code>, and <code>sequenceNonUnit
warn</code> have the obvious effect on elaboration.  The annotations
<code>warnUnused true</code> and <code>forceUsed</code> work in conjunction&#8201;&#8212;&#8201;warning on
any identifiers that do not contribute to the exported modules, and
preventing warnings on exported modules that are not used in the
remainder of the program.  Many of the
<a href="MLBasisAvailableLibraries">available libraries</a> are delivered with
these annotations.</p>
</div>
</div>
</div>
</div>
<div id="mlton-footer">
<div id="mlton-footer-text">
<div>
Last updated Thu Oct 21 15:53:06 2021 -0400 by Matthew Fluet.
<a href="https://github.com/MLton/mlton/commits/master/doc/guide/src/MLBasisAnnotationExamples.adoc">Log</a>
<a href="https://github.com/MLton/mlton/edit/master/doc/guide/src/MLBasisAnnotationExamples.adoc">Edit</a>
</div>
</div>
</body>
</html>