Sets, types and type checking
The blog post explains type theory and type-checking, highlighting their importance in programming languages for error detection, optimization, and understanding code, while introducing fundamental types and intersection types.
Read original articleThe blog post discusses the fundamentals of type theory and type-checking, detailing their significance in programming languages. It begins by explaining the purpose of type-checking, which is to ensure that programs are sound by validating the types of expressions and preventing errors, such as multiplying a number by a string. The author emphasizes that types provide essential information for error detection, optimization, and aiding programmers in understanding and structuring code. Types categorize data based on properties, allowing for reasoning about data throughout a program's lifecycle. The post also distinguishes between types and sets, noting that types are constructed based on properties rather than predicates. It introduces fundamental types like "any" and "never," explaining their roles in type hierarchies. The author discusses binary conjugations of types, particularly intersection types, which combine properties from two types, and their practical applications in languages like TypeScript. The post serves as a foundational overview for readers interested in type theory, with the promise of more advanced topics in future posts.
- Type-checking ensures program soundness by validating expression types.
- Types provide crucial information for error detection, optimization, and code understanding.
- Types categorize data based on properties, facilitating reasoning about data.
- The post introduces fundamental types "any" and "never" and their significance.
- Intersection types combine properties from two types, useful in languages like TypeScript.
Related
Parse, Don't Validate
The article explores type-driven design in programming, emphasizing "Parse, don’t validate" in Haskell. It showcases using types for robust code, avoiding errors, and enhancing input parsing efficiency in various tasks.
Types as Interfaces
The article explores using wrapper types like Msg and Timestamped in Haskell to annotate data without modifying existing types directly. It discusses challenges in composing annotated types and suggests using typeclasses for solutions. Emphasizes simplifying code for essential variants.
An approach to optimizing TypeScript type checking performance
The article outlines strategies to optimize TypeScript's type checking performance, addressing issues like sluggish IDE responsiveness and compile times, particularly due to performance regressions in TypeScript 5.3.
A systematic approach to deriving incremental type checkers (2020)
The paper presents a method for deriving incremental type checkers using Datalog, enhancing adaptability and efficiency in type systems while supporting various features like operator overloading and local type inference.
Mastering JavaScript Type Detection: Techniques and Best Practices
The guide on JavaScript type detection explains techniques for identifying data types, covering primitive and reference types, and methods like `typeof`, `instanceof`, `Object.prototype.toString.call`, and `Array.isArray`.
No, not true!
As the author correctly states earlier in the post, unions are not an exclusive-or relation. Unions are often made between disjoint types, but not always.
This becomes important when T itself is nullable. Let's say T is `U | null`. `Option<Option<U>>` in Rust has one more inhabitant than `U | null | null` in TypeScript - `Some(None)`.
Union types can certainly be very useful, but they are tricky because they don't compose like sum types do. When writing `Option<T>` where T is a generic type, we can treat T as a totally opaque type - T could be anything and the code we write will still be correct. On the other hand, union types pierce this opacity. The meaning of `T | null` and the meaning of code you write with such a type does depend on what T is at runtime.
Similar to this, I proposed inequality types for TS. They allow constraining a number range. For example, it is possible to have the type "a number that is larger than 1". You can combine them using intersection types, forming intervals like "a number between 0 and 1". Because TS has type narrowing via control flow, these types automatically come forward if you do an "if (a<5)". The variable will have the type "(<5)" inside the if block.
You can find the proposal here [1]. Personally I think the effort for adding these isn't worth it. But maybe someone likes it or takes it further.
`any`, however, is not `top`, it is `break_the_type_system`. The top type in TS is `unknown`.
I think they might have meant "entities" instead of "entries?"
The term "diagonal identity" seems to be non-standard as well?
I didn't feel satisfied with the explanation in TFA.
Are these even types? I always mentally filed closures under "implementation detail of nested functions".
Related
Parse, Don't Validate
The article explores type-driven design in programming, emphasizing "Parse, don’t validate" in Haskell. It showcases using types for robust code, avoiding errors, and enhancing input parsing efficiency in various tasks.
Types as Interfaces
The article explores using wrapper types like Msg and Timestamped in Haskell to annotate data without modifying existing types directly. It discusses challenges in composing annotated types and suggests using typeclasses for solutions. Emphasizes simplifying code for essential variants.
An approach to optimizing TypeScript type checking performance
The article outlines strategies to optimize TypeScript's type checking performance, addressing issues like sluggish IDE responsiveness and compile times, particularly due to performance regressions in TypeScript 5.3.
A systematic approach to deriving incremental type checkers (2020)
The paper presents a method for deriving incremental type checkers using Datalog, enhancing adaptability and efficiency in type systems while supporting various features like operator overloading and local type inference.
Mastering JavaScript Type Detection: Techniques and Best Practices
The guide on JavaScript type detection explains techniques for identifying data types, covering primitive and reference types, and methods like `typeof`, `instanceof`, `Object.prototype.toString.call`, and `Array.isArray`.