Subject: typescript [was: Re: [xsl] How to write (existential) predicates with maps/Why is there no effective boolean value for a map?] From: "Liam R. E. Quin liam@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 13 Feb 2019 11:08:25 -0000 |
On Wed, 2019-02-13 at 08:46 +0000, Mukul Gandhi gandhi.mukul@xxxxxxxxx wrote: > Sorry, if this is off topic. It is. I have changed the subject line, but it is also getting off the mailing listbs topic. Ibll 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, > https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html > 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. > A > Student object is being created (with the let statement), and it is > passed > to the greeter function. The greeter function is defined to accept > Person > (interface). In the above program, there is no syntactic link between > Student and Person (class Student is not written implementing the > interface > Person, and the structures of class Student and interface Person are > different 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 didnbt 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 itbs 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 -- 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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to write (existential, Mukul Gandhi gandhi. | Thread | Re: typescript [was: Re: [xsl] How , Dimitre Novatchev dn |
Re: [xsl] How to write (existential, Mukul Gandhi gandhi. | Date | Re: typescript [was: Re: [xsl] How , Dimitre Novatchev dn |
Month |