You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer: New Crystal developer, so this issue may lack a deeper understanding of the language. (P.S.—loving it so far!)
What aspect of the language would you like to see improved? Union Types are very wonky at the moment, especially in "complex" data structures.
What are the reasons? If you type a variable as a complex data type—say as an array or a map—you cannot assign it to a "pure valued" data structure even if logically it is valid.
Include practical examples to illustrate your points. The following example wouldn't work because you are trying to assign purely Int32 or Float64 hashes into a union hash. Logically however, all of the below hashes should be valid under the union. The same thing applies for arrays, and probably more data types that I simply haven't tried this with yet.
Optionally add one (or more) proposals to improve the current situation. I've never coded a compiler before, but perhaps for union types with complex data structures, rather than comparing the raw data type, you do some kind of a recursive check to see that all values within it fit the union type spec? It sounds kind performance costly, I guess, but I presume this is what other languages (e.g. TypeScript) do?
The text was updated successfully, but these errors were encountered:
Duplicate of #9797.
The underlying issue isn't actually union types, this is an application for covariance/contravariance which is tracked and explained in #3803. If you have any questions, feel free to ask. But I'm closing this as a duplicate.
Discussion
Disclaimer: New Crystal developer, so this issue may lack a deeper understanding of the language. (P.S.—loving it so far!)
Union Types are very wonky at the moment, especially in "complex" data structures.
If you type a variable as a complex data type—say as an array or a map—you cannot assign it to a "pure valued" data structure even if logically it is valid.
The following example wouldn't work because you are trying to assign purely
Int32
orFloat64
hashes into a union hash. Logically however, all of the below hashes should be valid under the union. The same thing applies for arrays, and probably more data types that I simply haven't tried this with yet.I've never coded a compiler before, but perhaps for union types with complex data structures, rather than comparing the raw data type, you do some kind of a recursive check to see that all values within it fit the union type spec? It sounds kind performance costly, I guess, but I presume this is what other languages (e.g. TypeScript) do?
The text was updated successfully, but these errors were encountered: