Skip to content
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

Type declarations: Constructor functions? #1506

Open
ChristianGruen opened this issue Oct 17, 2024 · 0 comments
Open

Type declarations: Constructor functions? #1506

ChristianGruen opened this issue Oct 17, 2024 · 0 comments
Labels
Discussion A discussion on a general topic. Enhancement A change or improvement to an existing feature XQuery An issue related to XQuery

Comments

@ChristianGruen
Copy link
Contributor

I’ve tagged this as a discussion issue:

Would it make sense to declare constructor functions for the new XQuery type declarations, similar to what we now have for records, or do we believe that’s over the top?

It might improve typing in complex code, and it would allow us to write things like:

declare type world:continent as enum('Africa', 'America', 'Asia', 'Australia', 'Europe');
world:continent('Africa')

For the type above, an implicit constructor function would be created that would simply coerce its argument to the declared type:

declare function world:continent($value) as world:continent { $value };

One current drawback is that this only works for prefixed types (see #657), whereas it’s possible to define types without prefix, and reference them in local type declarations:

declare type continent as enum('Africa', 'America', 'Asia', 'Australia', 'Europe');
let $c as continent := 'Africa'
return $c
@ChristianGruen ChristianGruen added XQuery An issue related to XQuery Enhancement A change or improvement to an existing feature Discussion A discussion on a general topic. labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion A discussion on a general topic. Enhancement A change or improvement to an existing feature XQuery An issue related to XQuery
Projects
None yet
Development

No branches or pull requests

1 participant