That's called a struct (or class) elsewhere.
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.
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.
For those new to this, good search terms are "row polymorphism", "extensible records", and "polymorphic variants".
Any of the mainstream functional languages (which are most likely to have type inference) can infer the types of all functions, unless you use funky language extensions that make type inference undecidable. Rust has a Hindley-Milner system, so it should be able to "infer recursive functions" too (but I can't say for sure since I don't use it).
Also, mainstream functional languages aren't truly mainstream: I'd struggle to find devs who could help me in consulting gigs.
let rec factorial n =
if n = 0 || n = 1 then 1
else n * factorial (n - 1)
F# factorial n =
if n < 2
then 1
else n * factorial (n - 1)
I think the OCaml version will look almost exactly like the F# one.You don't need to have used other languages to see there's no problem -- just Google -- haskell recursive factorial type inference
TypeScript was the first time I ever used a static language without feeling like it was getting in the way or I was losing the power of a dynamic language. So no, they didn't learn their mistake from using Python, they were just coaxed into using an incredible language since, barring masochism, you must compile from something into JavaScript nowadays, and TypeScript is an absolute pleasure.
- Type inference for the laziest. Hands down better than Scala, Swift, or Rust. The only language I've ever used that can infer recursive functions:
- You can define mix-typed maps without a sweat: const defaults = { debug: false, title: 'Banana', width: 100 }- And as a bonus you can suck the type out for later use:
- You can mix types without the compiler demanding umpteen incantations.- Gloriously simple union types.
- Regex types are coming! (e.g. all strings that look like a URL)
- You can type the API of some hidden dynamically-typed insanity if needed.
- You get a REPL for free, and it's pretty easy to debug production code if you haven't mangled all your names.
- Haven't figured how to type something? Want to prototype something quickly? No worries! Your code will still compile.