You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have no idea right now how this would work or what it would look like! However, I have a feeling that the ability to define a sealed type of enumerations could be useful.
For example if I have a function like compute-checksum($algorithm, $data), it might be useful if I could define that the $algorithm is one of a number of enumerated (supported) values and nothing else.
A further example to start a discussion:
declare enumeration local:animal := {
CAT
DOG
PIG
};
declarefunctionlocal:sound($animal asenumeration(local:animal)) as xs:string {
if ($animal eq local:animal:CAT) then"meow"elseif ($animal eq local:animal:DOG) then"woof"else"oink"
};
The text was updated successfully, but these errors were encountered:
Enumeration types are great, but a new kind of type is a big addition to the language: it needs lots of infrastructure like subsumption rules etc.
One way to handle this is like I tried to do with locally-defined union types: define it simply as a convenient way of defining an atomic type that is a restriction of xs:string with an enumeration facet, with the same semantics as if it was imported from a schema. Note that you would then be allowed to pass an enumeration to a function that expects a string, but not the other way around...
Michael Kay
Saxonica
On 24 Nov 2018, at 03:27, Adam Retter ***@***.***> wrote:
I have no idea right now how this would work or what it would look like! However, I have a feeling that the ability to define a sealed type of enumerations could be useful.
For example if I have a function like compute-checksum($algorithm, $data), it might be useful if I could define that the $algorithm is one of a number of enumerated (supported) values and nothing else.
A further example to start a discussion:
declare enumeration local:animal := {
CAT
DOG
PIG
};
declare function local:sound($animal as local:animal) as xs:string {
if ($animal eq local:animal:CAT) then
"meow"
else if ($animal eq local:animal:DOG) then
"woof"
else
"oink"
};
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#17>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ACSIIhad86WMSOBZTMc-qgfkbYKm4M8dks5uyLypgaJpZM4YxQN9>.
I have no idea right now how this would work or what it would look like! However, I have a feeling that the ability to define a sealed type of enumerations could be useful.
For example if I have a function like
compute-checksum($algorithm, $data)
, it might be useful if I could define that the$algorithm
is one of a number of enumerated (supported) values and nothing else.A further example to start a discussion:
The text was updated successfully, but these errors were encountered: