OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] XPath 1.5? (was RE: [xml-dev] typing and markup)

[ Lists Home | Date Index | Thread Index ]


Elliotte Rusty Harold wrote:

> At 12:52 PM -0700 5/7/02, Jonathan Robie wrote:
> >Without the cast, max() would sort according to the string value,
> >not the decimal value.
>
> I would propose more simply that max() and similar functions always
> treat their arguments as numbers. I personally have never heard of a
> max() function that operates on strings anyway.

It does in Haskell:

	Prelude> max 1 2
	2
	Prelude> max "abc" "def"
	"def"
	Prelude> :type max
	max :: Ord a => a -> a -> a

In C++, 'max' works on any type 'T' for which
bool T::operator<(const T&) or bool ::operator<(const T&,const T&)
is defined (which includes strings).

That said, I strongly agree that for XQuery it makes more
sense to have type-specific functions.  Like you said:

> In brief, I suggest if you
> pass something to a function that expects a number, it's converted to
> a number. If you pass something to a function that expects a date,
> it's converted to a date. No muss, no fuss.

IMO, that is an eminently more sensible approach for XQuery.

With class-based polymorphism a la Haskell, a polymorphic 'max'
makes sense.  With ad-hoc overloading a la C++, it's still workable.
But XQuery has a dynamic type system at its base with an optional
static type system added on, much like Common Lisp.  In languages
like that, overloaded functions are _very_ tricky to specify well,
tedious to implement, and unpredictable in use.  It's workable
if the type hierarchy is well thought-out, like the Lisp numeric
tower is.  Looking at the mixed bag of XSD primitive types,
I have serious doubts.


--Joe English

  jenglish@flightlab.com




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS