Are unions in Crystal considered as tagged unions (sum type)?

@epoch Only alias is the equivalent to Rust because in the next version apparently you will be able to do:

case ip
in V4
in V6
end

and if you forget one of the cases you will get a compile error. Using classes or modules you will not get an error. And in Rust you get an error, so only alias is equivalent.

Ideally you would be able to use classes or modules with a sealed annotation but it seems not many like the idea so maybe it won’t happen. It would be nice if defining a closed group of types would be orthogonal to being able to check they are all covered in a case, like you can do in Scala and Kotlin, but not in Crystal.

1 Like