Earlier quoted context omitted.
I'm not sure what you mean by "not gaining anything of significance." Go without interfaces (and for simplicity let's ignore 1.18's generics for a moment) would not be a useful language at any significant scale. You'd end up with a lot of "by hand" interfaces of structs full of function pointers (or method closures), only without the compiler support. Nor am I sure exactly what "confusion" is being increased.
> I'm not sure what you mean by "not gaining anything of significance." Go without interfaces (and for simplicity let's ignore 1.18's generics for a moment) would not be a useful language at any significant scale. Why would go not have interfaces? Where did you make that up from? Go would have nominative interfaces Like most other languages.
Why don't more languages offer flow typing?
101–110 of 127 posts
Re: Why don't more languages offer flow typing?
#102Hafiz writes: > almost every enterprise Java codebase I've had to work with has observed this pattern of testing whether an object is an instance of particular subclass, and using that to drive further computation. Even in the presence of such tests, Java demands that the author cast their objects appropriately. Of course you can always introduce an intermediate variable after the test, but I argue that this is still…
if (!(node instanceof DomNode.Element)) {
return new RenderNode.Noop(/* ... */);
}
Layout layout = node.layout;
return new RenderNode.Styled(layout, /* ... */);Re: Why don't more languages offer flow typing?
#103Hafiz writes: > almost every enterprise Java codebase I've had to work with has observed this pattern of testing whether an object is an instance of particular subclass, and using that to drive further computation. Even in the presence of such tests, Java demands that the author cast their objects appropriately. Of course you can always introduce an intermediate variable after the test, but I argue that this is still…
In this example, it's why Java added sealed interfaces, otherwise left with ∞ - 1 possibilities. if (!(node instanceof DomNode.Element)) { return new RenderNode.Noop(/* ... */); } Layout layout = node.layout; return new RenderNode.Styled(layout, /* ... */);
Re: Why don't more languages offer flow typing?
#104Earlier quoted context omitted.
For consts and function arguments yes, I think. But you could have some mutable variable or field whose value depends on runtime state. In that case, you could have an actual polymorphic type.
But the previous example isn't that case. if (c.type === 'a') { /* c is of type A here */ } This is dynamic typing, this code is checked at runtime, and it's leveraged statically.
Re: Why don't more languages offer flow typing?
#105Earlier quoted context omitted.
But the previous example isn't that case. if (c.type === 'a') { /* c is of type A here */ } This is dynamic typing, this code is checked at runtime, and it's leveraged statically.
Yes, that's correct. In the GP example, c was const, so the type can be determined at compile time.
const c: C = Math.random() Re: Why don't more languages offer flow typing?
#106The answer is simple: because other languages don't need it - they have different features to deal with it. The author even mentions it: pattern matching. Just that he picks a language that doesn't support union-types. But that doesn't mean that flow typing would be necessary here - it means that the language(s) should support union-types and extend their pattern matching accordingly. In fact, I would say that flow t…
You need flow typing when you do pattern matching on generalized abstract data type (GADT). Here is an example in Java sealed interface Foo permits Impl {} // union type record Impl() implements Foo {} // product type T m(Foo foo) { return switch(foo) { case Impl impl -> "hello"; // flow typing T=String }; }
Re: Why don't more languages offer flow typing?
#107This is not a complete answer, but covers some languages. If you program too exclusively in dynamically-typed languages, you can be too used to not thinking about how physically large your types are, because you work in a world where everything is boxed, and allocations so plentiful you don't even hardly have a way of thinking about them because your language does them at the drop of a hat, and so on. But there are m…
Re: Why don't more languages offer flow typing?
#108So I've been working on a personal project which is in a mix of C++ and TypeScript -- partially because of practicality and partially to learn TypeScript, and I'm really liking the language. One question I have is whether there's any possibility that TypeScript could, in the long run, gain performance advantages over pure JS? That the compiler could leave behind some type information artifacts so that V8 (or similar)…
I really enjoy Typescript, but every time I use it I think to myself, this would be so much better if were built on top of something other than JavaScript. Maybe AssemblyScript or some other TS to WASM target will come along with a better underlying type system and a good standard library. Dare to dream.
Re: Why don't more languages offer flow typing?
#109Earlier quoted context omitted.
This is amazing, but I don't understand the justification : > Since their types specify the same length, the type-checker knows we can ignore the 'zip Nil Cons' or 'zip Cons Nil' cases. Specifically, I have trouble understanding "their types specify the same length". Whose types ?
The types of the vectors: the length is a generic parameter to the type. So a Vec 4 Int and a Vec 5 Int are different types .
That's really awesome. Thanks for the explanation.