Most languages have poor support for structural types though. If you try and join two records together (like a SQL join), what will your favourite language infer then?
C# has anonymous types which is pretty much the same thing. Though I prefer to declare actual types for most usecases, I'll only use anonymous types for intermediate results and such.
I certainly don't mean to knock nominal types. But I think structural types are more fundamental. A language would only need a single "newtype" or "nominal" keyword to create nominal types from structural types.
C#'s anonymous type shares some flexibility of structural type system even though it still a nominal type.
> A language would only need a single "newtype" or "nominal" keyword to create nominal types from structural types.
I think you also can add `structural` keyword & apply structural type system in generally nominal type system as well if we're talking about adding feature.
dictionaries generally aren't guaranteed to contain an entry for every possible value of the key type. while you could implement the colors example with a dictionary, ideally you'd want the type system to assure that given a Color, there will be a string associated with it
It's not a dictionary (type-wise). "as const" is the magic ingredient.
Most languages have poor support for structural types though. If you try and join two records together (like a SQL join), what will your favourite language infer then?
C# has anonymous types which is pretty much the same thing. Though I prefer to declare actual types for most usecases, I'll only use anonymous types for intermediate results and such.
I certainly don't mean to knock nominal types. But I think structural types are more fundamental. A language would only need a single "newtype" or "nominal" keyword to create nominal types from structural types.
Why structural is more fundamental?
C#'s anonymous type shares some flexibility of structural type system even though it still a nominal type.
I think you also can add `structural` keyword & apply structural type system in generally nominal type system as well if we're talking about adding feature.Claude is "very good" in applying >var< continuously :-D
dictionaries generally aren't guaranteed to contain an entry for every possible value of the key type. while you could implement the colors example with a dictionary, ideally you'd want the type system to assure that given a Color, there will be a string associated with it
Sounds like enums with extra steps.
Enums aren't type safe in typescript
Sounds like a major flaw.
it’s Enuma associated with data without having to repeat yourself
If you have to define the Enums in one place and then repeat them all in another just to associate data with each one you’ve failed
Maybe you can elaborate but enums in Java or Kotlin easily have data associated with them.