Commit 1b61095f authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-01-31 14:39:11 by beppe] Empty log message

Original author: beppe
Date: 2004-01-31 14:39:11+00:00
parent 5e1300ca
......@@ -19,13 +19,80 @@ test it on the <a href="cgi-bin/cduce">online interpreter</a>.
<p>
CDuce, statically detects a large class of error and tries to help their
debbugging by providing precise error messages and, in case of type errors, by
debugging by providing precise error messages and, in case of type errors, by
showing a description (we call it a "sample") of specific values that would make
the computation fail.
</p>
<p>
CDuce signals the classic syntax errors as well as those for instance of unbound variables. It also checks that pattern matching is exhaustive
<footnote>
It checks it in functions, <code>match</code>, and <code>map</code> expressions, but
not for <code>transform</code> and <code>xtransform</code> for which a default branch
returning the empty sequence is always defined
</footnote>.
For instance if we declare the type <code>Person</code> defined in Section "<local href="tutorial_overloading"/>" and try the following definition:
</p>
<sample><![CDATA[
fun name (Person -> String)
| <person gender = {{"F"}}>[ n ;_] -> n
]]></sample>
<p> then we obtain the following message error:</p>
<sessionsample><![CDATA[
Error at chars 228-298:
{{%%fun name (Person -> String)
| <person gender = "F">[ n ;_] -> n%%}}
This pattern matching is not exhaustive
Residual type:
<person gender = [ 'M' ]>[ Name Children ]
Sample:
<person {| gender = [ 'M' ] |}>[ <name {| |}>[ ] <children {| |}>[ ] ]
]]></sessionsample>
<p>
This error message tells us three things: (1) that pattern matching is not
defined for all the possible input types (as we forgot the case when the
attribute is <code>"M"</code>); (2) it gives us the exact type of the values of
the type we have forgotten in our matching (in this case this is exactly
<code>MPerson</code>); (3) it shows us a "sample" of the residual type, that is
a simplified representation of a value that would make the expression fail (in
this case it shows us the value <code>&lt;person gender="M">[ &lt;name>[ ]
&lt;children>[ ] ]</code>).
</p>
<note>Samples are a simplified representation of values in the sense that they show
only that part of the value that is relevant for the error and may omit other parts
that are needed for an effective value.
</note>
<b style="color:#FF0080">TO BE FINISHED (show example of unused type variable as a typo in a type name) show example of samples</b>
<section title="Warnings">
<p>
CDuce use warnings to signal possible subtler errors. So for instance it issues a warning whenever a capture variable of a pattern is not used in the subsequent expression. This is very useful for instance to detect misprinted types in patterns such as in:
</p>
<sample><![CDATA[
transform [ 1 "c" 4 "duce" 2 6 ] with
x & {{Sting}} -> [ x ]
]]></sample>
<p> The intended semantics of this expression was to extract the sequence of all
the strings occuring in the matched sequence. But because of the typo in
<code>St(r)ing</code> the transformation is instead the identity function:
<code>Sting</code> is considered as a fresh capture variable. CDuce however
detects that <code>Sting</code> is never used in the subsequent expression
and it pinpoints the possible presence of an error by issuing the
following warning:
</p>
<sessionsample><![CDATA[
Warning at chars 42-60:
{{%% x & Sting -> [ x ]%%}}
The capture variable Sting is declared in the pattern but not used in
the body of this branch. It might be a misspelled or undeclared type
or name (if it isn't, use _ instead).
%%transform [ 1 "c" 4 "duce" 2 6 ] with
x & Sting -> [ x ]%%
- : [ 1 [ 'c' ] 4 [ 'duce' ] 2 6 ] =
[ 1 "c" 4 "duce" 2 6 ]
Ok.
]]></sessionsample>
</section>
</box>
......
......@@ -89,9 +89,9 @@ where <code>%%p%%</code> is a pattern and <code>%%e%%</code>,
<code>%%e%%</code> and <code>%%e'%%</code> stand for generic expression, so it is useless to run
this could (you would just obtain an error signaling that <code>e</code> is
not bound or that the quote in <code>e'</code> is not closed). This is true also in general in what follows: code without
italicized text can be copy and pasted in the on-line prototype as they are
(sometime just after having pasted the declaration of the types they use);
this is not possible when the code contains italicized text.
italicized text can be copied and pasted in the on-line prototype as they are
(of course you must first paste the declarations of the types they use);
this is not possible whenever the code contains italicized text.
</note>
<p>
Patterns are much more than simple variables. They can be used to decompose
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment