Live data from Hacker News

So you want to write a type checker (2014)

languagengine.co

41–50 of 103 posts

Re: So you want to write a type checker (2014)

#41
post #23

Earlier quoted context omitted.

My point exactly. If people who liked type systems could stand to use the JS type system (and I only barely managed to write type system without scare quotes), we wouldn't have TypeScript. Or Cofeescript. Or Purescript. Or Elm. Or Fable. Or Flow. Or even ES6.

What's wrong with TypeScript?

I'm having a hard time discerning his point based on the languages he listed. I think his point was that the type theorists weren't fans of JS so they built languages that compiled to it, but CoffeeScript and ES6 don't have type systems either, so either he isn't very familiar with the languages he listed or he's making a different point.

Re: So you want to write a type checker (2014)

#42
post #30

Earlier quoted context omitted.

Don't underestimate Typescript. Sure, it's somewhat restricted by the "superset of JS" property, but you still get stuff like ADTs with exhaustiveness checking.

TS doesn’t have exhaustiveness checking

I know TS discriminated unions may not be the most elegant construct in the world, but in what way is the check via the never type (as a return or assertion parameter after the switch) not an exhaustiveness check?

Re: So you want to write a type checker (2014)

#44

Earlier quoted context omitted.

My point exactly. If people who liked type systems could stand to use the JS type system (and I only barely managed to write type system without scare quotes), we wouldn't have TypeScript. Or Cofeescript. Or Purescript. Or Elm. Or Fable. Or Flow. Or even ES6.

maybe because browsers and backwards compatibility exist and we cant just change the language as we please?

webassembly with native dom access will free us from the earthly limitations of javascript.

...at least that's when i'm planning to finally learn frontend development

Re: So you want to write a type checker (2014)

#45
post #4

Earlier quoted context omitted.

You might want to give this a look: https://github.com/Microsoft/TypeScript

TypeScript, the language which only just this month added a flag to turn off their completely incorrect subtyping rules for functions! A flag! I remember reporting this bug years ago, and they said it was "by design, since JS programmers prefer to think of functions as covariant in their input". Well, I prefer to think of 2+2 as equalling 5.

I don't know nearly enough about type systems to understand this. Can you explain what subtyping rules are, and how TypeScript's are wrong? And can you explain what "covariant in their input" means?

Re: So you want to write a type checker (2014)

#46

Earlier quoted context omitted.

TypeScript, the language which only just this month added a flag to turn off their completely incorrect subtyping rules for functions! A flag! I remember reporting this bug years ago, and they said it was "by design, since JS programmers prefer to think of functions as covariant in their input". Well, I prefer to think of 2+2 as equalling 5.

I don't know nearly enough about type systems to understand this. Can you explain what subtyping rules are, and how TypeScript's are wrong? And can you explain what "covariant in their input" means?

Here is a good and down-to-earth explanation: https://www.stephanboyer.com/post/132/what-are-covariance-an...

Re: So you want to write a type checker (2014)

#47

Earlier quoted context omitted.

TypeScript, the language which only just this month added a flag to turn off their completely incorrect subtyping rules for functions! A flag! I remember reporting this bug years ago, and they said it was "by design, since JS programmers prefer to think of functions as covariant in their input". Well, I prefer to think of 2+2 as equalling 5.

I don't know nearly enough about type systems to understand this. Can you explain what subtyping rules are, and how TypeScript's are wrong? And can you explain what "covariant in their input" means?

Covariant: A variable needs to have an Animal. You can put a Cat in the variable.

Contravariant: A variable needs to have a function that accepts Animals. You can't put a function that accepts only Cats, or it will crash on other kinds of animal. But you can put a function that accepts all LivingThings.

So when something is covariant you can use a more specific type, and when it's contravariant you can use a more generic type.

When it comes to function parameters, typescript lets you use either. You can replace any type with any related type, even if you're going in the wrong direction. They did this to make certain use cases simpler, at the cost of weaker typing.

Re: So you want to write a type checker (2014)

#48
post #26
post #5

Earlier quoted context omitted.

literally :) EDIT: Oh, the hard earned karma is leaving me. :) I apologize for the irony! In a nicer way: if you're interested in type theory then javascript is not the language to look at. I'm not even sure if typescript helps here, since the typing mechanism is fairly simple (and I don't mean it's not useful -- just not very advanced).

Well, it's kind of like "if you're interested in type theory then bash will not arouse your intellectual curiosity." Sure, but it's still a practical and kind of necessary part of the world, and if you take it for what it is, it's pretty nice.

I can't really agree with you. Yes, javascript is "good for what it is", but this kind of positive evaluation is only the result of that it (the language) pretty much can't be avoided when doing web development. Many things appear in a more positive light if they have been around you long enough, and you've gotten use to the experience.

I.e yes, bash is nice, but if it weren't the default shell in most systems I wouldn't ever think about switching to it voluntarily, nor be interested in learning it. It is useful because its so widely spread.

Post reply on HN