Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
7a781748
Commit
7a781748
authored
Jul 10, 2007
by
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
web/manual/types_patterns.xml
View file @
7a781748
...
...
@@ -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 a
n
<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))
&
{ y = b }
</code>
. A special syntax
makes this idiom more convenient:
<code>
{ x = a else (a:=1); y = b }
</code>
.
...
...
web/tutorial/patterns.xml
View file @
7a781748
...
...
@@ -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%%))
&
{ 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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment