Rendered at 07:10:07 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
PashaGo 18 hours ago [-]
Anonymous records feel like one of those features that are obviously useful once you work with JSON-heavy systems, but surprisingly uncommon in statically typed languages
Timwi 13 minutes ago [-]
If a statically typed language has no support for record type (or the support it does have is insufficient for your purposes) then you are forced to find other ways to express your logic, so over time those other ways start feeling more natural due to familiarity, and then you end up feeling that you don't need record types (or more extensive support for them), which in turn leads language designers/implementors to leave it out, and so the cycle repeats.
I'm not sure I agree that anonymous records are “obviously useful” when working with JSON. JSON is not typed, so if you want your deserialized JSON to be statically typed, you need to declare typed records outside of the JSON, so I'd say it's far more useful to use type declarations that are not anonymous.
That said, anonymous types are incredibly useful in general. I work with C# a lot and its support for them is rather shallow. In particular, there is no “with” expression equivalent.
vatsachak 1 days ago [-]
An anonymous record type in a language whose type system is an enum LangType in Rust is just HashMap<String, Box<LangType>>
My pet project requires an STLC with anonymous record types and type inference for anonymous records wasn't too bad
wavemode 18 hours ago [-]
Anonymous records aren't complex in principle. The main challenge Haskell has always faced in this area, is the simple fact that its type system (and syntax) weren't designed for anonymous records from the start, so they have to be shoehorned in without breaking existing semantics.
PureScript has much better support for row polymorphism for this reason.
18 hours ago [-]
antonvs 18 hours ago [-]
The article missed Go’s anonymous structs:
p := struct {
Name string
Age int
}{
Name: "Alice",
Age: 30,
}
Timwi 10 minutes ago [-]
Technically anonymous I suppose because the struct is not named, but the article is mostly about type inference while your example has every type made explicit.
I'm not sure I agree that anonymous records are “obviously useful” when working with JSON. JSON is not typed, so if you want your deserialized JSON to be statically typed, you need to declare typed records outside of the JSON, so I'd say it's far more useful to use type declarations that are not anonymous.
That said, anonymous types are incredibly useful in general. I work with C# a lot and its support for them is rather shallow. In particular, there is no “with” expression equivalent.
My pet project requires an STLC with anonymous record types and type inference for anonymous records wasn't too bad
PureScript has much better support for row polymorphism for this reason.