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

Subject: Re: typescript [was: Re: [xsl] How to write (existential) predicates with maps/Why is there no effective boolean value for a map?]
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Feb 2019 15:12:20 -0000
On Wed, Feb 13, 2019 at 3:08 AM Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Typescript uses structural typing, not named typing.

Actually this statement is not entirely correct -- a Typescript
programmer can use both. To achieve strict typing, which people like
me would prefer, just change:

   class Student { ...}


  class Student implements Person { ...}

I believe that offering differing typing choices (starting from no
typing at all -- all Javascript code is valid in Typescript as
Typescript is a superset of Javascript) is an intentionally-designed
flexibility in the language. Of course, many developers such as myself
would use just strict typing style, so that when the transpiler
reports typing errors one will correct them even before compile-time.


On Wed, Feb 13, 2019 at 3:08 AM Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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,
> >
> > 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,
> Available for XML/Document/Information Architecture/XSLT/
> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
> Web slave for vintage clipart

Current Thread