Hacker News new | ask | show | jobs
by yxhuvud 1075 days ago
Crystal union types are tagged as the actual type a variable contains is tracked.

I honestly have no idea how anything could work if they were not tagged. Like how on earth would you know what method to invoke?

1 comments

You should look into the union keyword in C :)

(Basically the programmer has to figure out how discrimination works - you’re kinda on your own).

But eh, that is not the case in crystal. You are not on your own - the language knows what a variable is during runtime and you have plenty of ways to dispatch between the types.