Type systems are leaky abstractions: the case of Map.take!/2
4 days ago
- #type-systems
- #elixir
- #programming-languages
- Type systems in dynamic languages can restrict expressive power, illustrated by the proposed Map.take!/2 function in Elixir.
- Map.take!/2 would raise an error if a key doesn't exist, unlike Map.take/2 which silently ignores missing keys.
- Current type signatures for Map.take!/2 are too broad, failing to specify the exact shape of the returned map.
- TypeScript's keyof operator offers a solution but has limitations, especially with dynamic key lists.
- Refactoring code can lead to type system violations, showing how type systems can work against best practices.
- Macros are proposed as a solution to enforce static guarantees on key lists, though they come with their own trade-offs.
- The article highlights the trade-offs between language simplicity and expressiveness when adding type systems to dynamic languages.