Skip to content

Commit

Permalink
Merge pull request #1696 from michaelhkay/1136-optional-param-names-i…
Browse files Browse the repository at this point in the history
…n-function-signature

1136 Optional names in typed function types
  • Loading branch information
michaelhkay authored Jan 15, 2025
2 parents 972ce90 + c491b92 commit e10bd9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 10 additions & 1 deletion specifications/grammar-40/xpath-grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2753,12 +2753,21 @@ ErrorVal ::= "$" VarName
</g:choice>
<g:string>(</g:string>
<g:zeroOrMore separator=",">
<g:ref name="SequenceType"/>
<g:ref name="TypedFunctionParam"/>
</g:zeroOrMore>
<g:string>)</g:string>
<g:string>as</g:string>
<g:ref name="SequenceType"/>
</g:production>

<g:production name="TypedFunctionParam" if="xpath40 xquery40 xslt40-patterns">
<g:optional>
<g:string>$</g:string>
<g:ref name="EQName"/>
<g:string>as</g:string>
</g:optional>
<g:ref name="SequenceType"/>
</g:production>

<g:production name="MapType" if="xpath40 xquery40 xslt40-patterns">
<g:choice>
Expand Down
26 changes: 24 additions & 2 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4043,6 +4043,7 @@ types</term> (such as <code>xs:integer</code>) and function types
<prodrecap ref="FunctionType"/>
<prodrecap ref="AnyFunctionType"/>
<prodrecap ref="TypedFunctionType"/>
<prodrecap ref="TypedFunctionParam"/>
<prodrecap id="ChoiceItemType" ref="ChoiceItemType"/>
<prodrecap ref="MapType"/>
<prodrecap ref="RecordType"/>
Expand Down Expand Up @@ -5201,6 +5202,10 @@ name.</p>
<term>FunctionTest</term>, <term>ArrayTest</term>,
<term>MapTest</term>, and <term>RecordTest</term>, with no
change in meaning.</change>
<change issue="1136" date="2025-01-12">
Parameter names may be included in a function signature; they are purely
documentary.
</change>
</changes>

<p>A <nt def="FunctionType">FunctionType</nt> matches selected <termref
Expand All @@ -5216,6 +5221,7 @@ name.</p>
<prodrecap role="xquery" ref="Annotation"/>
<prodrecap id="AnyFunctionType" ref="AnyFunctionType"/>
<prodrecap id="TypedFunctionType" ref="TypedFunctionType"/>
<prodrecap id="TypedFunctionParam" ref="TypedFunctionParam"/>
</scrap>


Expand Down Expand Up @@ -5243,10 +5249,22 @@ name.</p>
>subtype</termref> of the <nt def="TypedFunctionType"
>TypedFunctionType</nt>.</p>


<note><p>The keywords <code>function</code> and <code>fn</code> are synonymous.</p></note>

<p>If parameter names are included in a <nt def="TypedFunctionType">TypedFunctionType</nt>,
they are purely documentary and have no semantic effect. In particular, they
play no part in deciding whether a particular function item matches the
function type, and they never appear as keywords in function calls.
For example the construct
<code>function($x as node()) as xs:string</code> designates exactly the same type
as <code>function(node()) as xs:string</code>.</p>

<p>Any parameter names that are supplied must be distinct
<errorref spec="XQ" class="ST" code="0039"/>.</p>

<p>In consequence, a <nt def="TypedFunctionType">TypedFunctionType</nt>
may match certain maps and arrays, as described in <specref ref="id-map-test"/> and
<p diff="add" at="issue730">A <nt def="TypedFunctionType">TypedFunctionType</nt>
may also match certain maps and arrays, as described in <specref ref="id-map-test"/> and
<specref ref="id-array-test"/></p>


Expand All @@ -5269,6 +5287,10 @@ name.</p>
because the signature of the function item <code>fn:count#1</code>
is a subtype of <code>function(xs:string*) as item()</code>.
</p>

<note><p>The same type might also be written
<code>fn($x as xs:int, $y as xs:int) as xs:int</code>.</p></note>

</item>
<item role="xquery">
<p>
Expand Down

0 comments on commit e10bd9c

Please sign in to comment.