3 ms·
> You can define mix-typed maps without a sweat: const defaults = { debug: false, title: 'Banana', width: 100 } That's called a struct (or class) elsewhere.
by jstimpfle 9y ago
> You can define mix-typed maps without a sweat: const defaults = { debug: false, title: 'Banana', width: 100 }
That's called a struct (or class) elsewhere.
- resf 9y agoSpecifically structural record types, and many statically typed languages don't have them. (not Java, not C++, not Haskell, not Rust, yes Swift, yes OCaml)
- jstimpfle 9y agoWhat I wanted to point out is that typically a C struct is what you need. The common case is static keys and static value types but dynamic values. What are interesting use cases for more dynamic (i.e. non-fixed set of keys / types)? I mean, if you need something super-abstract and flexible, you are unlikely to need a built-in convenient syntax to hardcode such values.
- mrkgnao 9y ago, yes Purescript :) For those new to this, good search terms are "row polymorphism", "extensible records", and "polymorphic variants".
- fny 9y agoAn instance of mixed-type maps* Elsewhere one would have to define a struct/class and them create an instance. This becomes immensely helpful for the incredibly lazy with one off object definitions and wrapper types. If you introduce a class definition alongside an instance, you're now forced to manage two peices of code. The class definition and instance definition. In this case they're coupled which aides maintenance in my experience.