W3C home > Mailing lists > Public > public-qt-comments@w3.org > February 2016

[Bug 29422] New: Object-oriented programming lite

From: <bugzilla@jessica.w3.org>
Date: Sat, 06 Feb 2016 15:32:10 +0000
To: public-qt-comments@w3.org
Message-ID: <bug-29422-523@http.www.w3.org/Bugs/Public/>

            Bug ID: 29422
           Summary: Object-oriented programming lite
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Requirements for Future Versions
          Assignee: jim.melton@acm.org
          Reporter: benito@benibela.de
        QA Contact: public-qt-comments@w3.org
  Target Milestone: ---

If you want to work with an 3.1 array/map, it seems you always have to prefix
the functions with array:. array:tail, array:head, which is way too verbose.

The solution in other languages is object oriented programmnig, where you have
an object, and the methods are bound to it.
Scala shows how to combine functional programming with objects, but it really
Fortunately there is a simpler solution.

Since all functions are in a namespace, we just need to map/bind the namespace
to the types.

For example with a grammar rule like:

"declare" "type" "function" "namespace"  URILiteral "for" SequenceType

Then the user writes

declare type function namespace "http://www.w3.org/2005/xpath-functions/array"
for array(*);
declare type function namespace "http://www.w3.org/2005/xpath-functions/map"
for map(*);

and the functions are bound to their types.

Now what does it mean if the functions are bound to a type?

For this we need a symbol to access the bound functions. E.g. “::“ the C++
class member operator (-> or . would be nicer, but conflict with the allowed
names. Pascal's “^.” would work, too)

Then, similarly to the => operator.
For a sequence $s with clear type the expression $s::f($j) becomes Q{bound
namespace}f($s, $j)

With this the user can write:

[1,2,3]::size() to get 3


let $a as array(*) := [1,2,3] return $a::tail()::size()

It is not array or map specific.

You can do as well

declare type function namespace "http://www.w3.org/2005/xpath-functions/math"
for xs:double;

and then write 2e0::pow(10)::sqrt() instead of math:pow(2,10)=>math:sqrt()

Or if you define your own types in a schema, you can bind functions to those
E.g. you can define a type myxs:traffic-light, which is either "red", "green"
or "yellow" 
(perhaps also "yellow red" for European lights).
Then you can have a function whatever:next-phase($light as myxs:traffic-light)
as myxs:traffic-light
and write let $light as myxs:traffic-light := ... return $light::next-phase()
to get to the next phase.

This should not depend on static typing, since that is an optional feature,
so you can only use for expressions that have clear type, i.e. whose type can
be decided trivially.

These expressions are (at least):
- variables or function parameters declared with a type, e.g. $foo as
- treat and cast, e.g. ... treat as xs:integer
- function calls of functions declared with a return type, e.g. substring(...)
- literals, e.g. 4.5
- constructors, e.g. [1,2,3]

You are receiving this mail because:
You are the QA Contact for the bug.
Received on Saturday, 6 February 2016 15:32:13 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:58 UTC