[Top] [All Lists]

typescript [was: Re: [xsl] How to write (existential) predicates with maps/Why is there no effective boolean value for a map?]

2019-02-13 05:08:30
On Wed, 2019-02-13 at 08:46 +0000, Mukul Gandhi 
Sorry, if this is off topic.
It is. I have changed the subject line, but it is also getting off the
mailing list’s topic. I’ll answer because we can compare typescript's
interface-based type system to that of XSLT (briefly).

I've been reading about Typescript, during this thread. On the link,
following sample program appears,
[garbled gibberish here]

Ungarbling, i get,
class Student {
    fullName: string;
    constructor(public firstName: string, public middleInitial: string, public 
lastName: string) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;

interface Person {
    firstName: string;
    lastName: string;

function greeter(person : Person) {
    return "Hello, " + person.firstName + " " + person.lastName;

let user = new Student("Jane", "M.", "User");

document.body.innerHTML = greeter(user);

So you are asking, does a Student object confom to the Person
interface?  That is, does the object have the required public fields.
We can see by inspection that it does.

I'm not been convinced, how above typescript program can be correct.
Student object is being created (with the let statement), and it is
to the greeter function. The greeter function is defined to accept
(interface). In the above program, there is no syntactic link between
Student and Person (class Student is not written implementing the
Person, and the structures of class Student and interface Person are

Correct. However, the Student object has the same structure as a Person
object. Typescript uses structural typing, not named typing. This is
sometimes called duck typing, after a Monty Python sketch (if she
weighs the same as a duck she must be a witch).

Early XQuery drafts used structural typing, i think because (some of)
the developers perhaps didn’t have good understanding of XST and DTDs
tand the fact that name-based typing, with its explicit syntactic
links, was an essential part of XML.

Why is this? Because the point of XML is not trusting data at system
boundaries. That is a large part of why we have DTDs and XSD. Duck
typing says, if you say it’s a metric velocity and it has a number, i
believe you. Named typing says, a metricVelocityType and an
imperialVelocityType value are not compatible without conversion.

We ended up with named typing in XSLT, XPath and XQuery, thankfully.
Its less convenient for some things, but a better cultural fit, and
more suited to the sort of tasks we might attempt.


Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Web slave for vintage clipart http://www.fromoldbooks.org/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>