|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] typescript [was: Re: How to write (existential) predi
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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








