Skip to content
/ data.xq Public

An XQuery 3.0 library for defining algebraic data types, and performing structural pattern matching on them.

License

Notifications You must be signed in to change notification settings

jpcs/data.xq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

data.xq

An XQuery 3.0 library for defining algebraic data types, and performing structural pattern matching on them. This can be used to define complex data structures and the operations on them.

Author: John Snelson June 28, 2012

Version: 0.1

Table of Contents

Functions

declare($decl as element()
) as  function(*)*

Returns a sequence of constructor functions for the XML type description passed in as an argument. One constructor function is returned for each of the sub-types described. The constructor functions can be called to construct an instance of the type, passing in the values required the specific sub-type being created.

An example of an XML description is:

 <Maybe>
   <Nothing/>
   <Just><data:Sequence/></Just>
 </Maybe>
 

This defines a type named "Maybe", with two sub-types named "Nothing" and "Just". The "Nothing" constructor function takes no arguments, and store no additional data. The "Just" constructor function takes a single argument which is an arbitrary sequence. Passing this type description to this function will return two constructor functions, one for each sub-type.

Another example of an XML description is:

 <Tree>
   <Empty/>
   <Leaf><data:Sequence/></Leaf>
   <Node><Tree/><Tree/></Node>
 </Tree>
 

This defines a type named "Tree", with three sub-types named "Empty", "Leaf", and "Node". The "Node" constructor function takes two arguments, each of which will be type checked as a "Tree" object during construction.

Params

  • $decl as element(): An XML description of an algebraic data type.

Returns

  • function(*)*: A sequence of constructor functions for the given algebraic type description.
declare($decl as element(),$type-check as xs:boolean
) as  function(*)*

Returns a sequence of constructor functions for the XML type description passed in as an argument. One constructor function is returned for each of the sub-types described. The constructor functions can be called to construct an instance of the type, passing in the values required the specific sub-type being created.

An example of an XML description is:

 <Maybe>
   <Nothing/>
   <Just><data:Sequence/></Just>
 </Maybe>
 

This defines a type named "Maybe", with two sub-types named "Nothing" and "Just". The "Nothing" constructor function takes no arguments, and store no additional data. The "Just" constructor function takes a single argument which is an arbitrary sequence. Passing this type description to this function will return two constructor functions, one for each sub-type.

Another example of an XML description is:

 <Tree>
   <Empty/>
   <Leaf><data:Sequence/></Leaf>
   <Node><Tree/><Tree/></Node>
 </Tree>
 

This defines a type named "Tree", with three sub-types named "Empty", "Leaf", and "Node". The "Node" constructor function takes two arguments, each of which will be type checked as a "Tree" object during construction.

Params

  • $decl as element(): An XML description of an algebraic data type.

  • $type-check as xs:boolean: Setting this argument to false turns off type checking during value construction, which can speed up data structure creation.

Returns

  • function(*)*: A sequence of constructor functions for the given algebraic type description.
type($v as item()
) as  element()

Returns the type of the value - that is, the child node in the XML type description that represents this value.

Params

  • $v as item(): A value, which must have been created by this library.

Returns

  • element(): The description element representing the type of the value.
describe($v
) as  xs:string

Returns a string serialization of the structure of the values. Non-algebraic types are serialized using the fn:string() function.

Params

  • $v: A sequence of values, which must have been created by this library.

Returns

  • xs:string: The serialization of the values.
match(
  $v as item(),
  $f1 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*),
  $f6 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

  • $f6 as function(*): A function, which is called with the values from the sixth sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*),
  $f6 as function(*),
  $f7 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

  • $f6 as function(*): A function, which is called with the values from the sixth sub-type of the type.

  • $f7 as function(*): A function, which is called with the values from the seventh sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*),
  $f6 as function(*),
  $f7 as function(*),
  $f8 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

  • $f6 as function(*): A function, which is called with the values from the sixth sub-type of the type.

  • $f7 as function(*): A function, which is called with the values from the seventh sub-type of the type.

  • $f8 as function(*): A function, which is called with the values from the eighth sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*),
  $f6 as function(*),
  $f7 as function(*),
  $f8 as function(*),
  $f9 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

  • $f6 as function(*): A function, which is called with the values from the sixth sub-type of the type.

  • $f7 as function(*): A function, which is called with the values from the seventh sub-type of the type.

  • $f8 as function(*): A function, which is called with the values from the eighth sub-type of the type.

  • $f9 as function(*): A function, which is called with the values from the ninth sub-type of the type.

match(
  $v as item(),
  $f1 as function(*),
  $f2 as function(*),
  $f3 as function(*),
  $f4 as function(*),
  $f5 as function(*),
  $f6 as function(*),
  $f7 as function(*),
  $f8 as function(*),
  $f9 as function(*),
  $f10 as function(*)
)

Performs structural pattern matching against the value. The pattern matching works by calling the function passed in in the same position as the sub-type of the value. Therefore the number of functions passed in as arguments must equal the number of sub-types of the value, and each function should have the same arity as its corresponding sub-type contains values.

Params

  • $v as item(): A value, which must have been created by this library.

  • $f1 as function(*): A function, which is called with the values from the first sub-type of the type.0: A function, which is called with the values from the tenth sub-type of the type.

  • $f2 as function(*): A function, which is called with the values from the second sub-type of the type.

  • $f3 as function(*): A function, which is called with the values from the third sub-type of the type.

  • $f4 as function(*): A function, which is called with the values from the fourth sub-type of the type.

  • $f5 as function(*): A function, which is called with the values from the fifth sub-type of the type.

  • $f6 as function(*): A function, which is called with the values from the sixth sub-type of the type.

  • $f7 as function(*): A function, which is called with the values from the seventh sub-type of the type.

  • $f8 as function(*): A function, which is called with the values from the eighth sub-type of the type.

  • $f9 as function(*): A function, which is called with the values from the ninth sub-type of the type.

  • $f10 as function(*): A function, which is called with the values from the tenth sub-type of the type.

Generated by xquerydoc

About

An XQuery 3.0 library for defining algebraic data types, and performing structural pattern matching on them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages