Commit 7a781748 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2005-06-07 21:57:41 by beppe] added "else"

Original author: beppe
Date: 2005-06-07 21:57:41+00:00
parent 1436f64c
......@@ -459,16 +459,16 @@ enumeration of the possible fields. The semi-colon between fields is optional.
Additionally, both for open and close record types,
it is possible to specify optional fields by using <code>=?</code>
instead of <code>=</code> between a label and a type.
For instance, <code>{ x = Int; y =? Bool }</code>
represents records with an <code>x</code> field of type
<code>Int</code>, an optional field <code>y</code> (when it is
present, it has type <code>Bool</code>), and no other field.
For instance, <code>{ x =? Int; y = Bool }</code>
represents records with a <code>y</code> field of type
<code>Bool</code>, and an optional field <code>y</code> (that when it is
present, has type <code>Int</code>), and no other field.
</p>
<p>
The syntax is the same for patterns. Note that capture variables
cannot appear in an optional field. A common idiom is to bind
default values to replace missing optinal fields:<code>
default values to replace missing optinal fields: <code>
({ x = a } | (a := 1)) &amp; { y = b }</code>. A special syntax
makes this idiom more convenient:
<code>{ x = a else (a:=1); y = b }</code>.
......
......@@ -235,6 +235,13 @@ attribute (the other is ignored by matching it with <code>..</code>), if it is p
while if the attribute is absent the default sub-pattern is used to assign the
variable a default value.
</p>
<p>
The use of pattern of the form <code>
({ label1= x } | (x := %%v%%)) &amp; { label2 = y }</code> is so common in handling
optional fields (hence, XML attributes) that CDuce has a special syntax for this
pattern: <code>
{ label1 = x else (x := %%v%%) ; label2 = y }</code>
</p>
</box>
......
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