Skip to content

Proposal for Annotation Sequence Types (XQuery only) #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions annotation-sequence-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Annotation Sequence Types (XQuery only)

**Author**: Reece H. Dunn. 67 Bricks.

This proposal adds annotation signatures to the XQuery type system.


## Description

It is not currently possible to access annotation information for a function in XQuery. Adding support for that to the XQuery Functions and Operators would need a way of specifying the annotations in return and parameter types, and thus be describable in the type system.

The new annotation types may also be used when specifying the type of the proposed annotation declarations.

The annotation type is modelled on the `FunctionTest` syntax. Annotation types cannot have a return type. For example:

1. `annotation(*)`
1. `%compatibility-annotation annotation()`
1. `annotation(xs:string)`
1. `annotation(variadic array(xs:string))` -- using the syntax from the variadic function parameter proposal.

The type matching rules should follow the same logic as matching functions, excluding the return type.

The type of an `Annotation` will be as follows:

1. The number of parameter types will match the number of arguments the annotation is called with.
1. If a parameter is a `StringLiteral`, it will have the type `xs:string`.
1. If a parameter is a `DoubleLiteral`, it will have the type `xs:double`.
1. If a parameter is a `DecimalLiteral`, it will have the type `xs:decimal`.
1. If a parameter is a `IntegerLiteral`, it will have the type `xs:integer`.

### Extending the Annotation Declaration Proposal

The type of an annotation declaration will match the type signature for that declaration.

The type of a named annotation reference will be the type signature of the matching annotation declaration.

If a named annotation reference refers to a variadic function parameter (if that proposal is accepted), the reference will refer to the expanded non-variadic signature, and the parameters after the last non-variadic parameter will have the type specified in the `ArrayTest` or `item()` if a type is not specified.


## Use Cases

Provide access to annotations in the XQuery code.

Make the XQuery type system more complete by making annotations part of the data model.


## Examples

let $post as annotation()? := annotation-for-function($f, %rest:POST#1)
return exists($post)


## Grammar

TBD.