> There are a few languages out there that don't support typecasting. I think SML was one, for example.
Haskell too, unless you explicitly opt in with Data.Typeable.
It's arguably true in a certainly commonly-used subset of C++ as well: this type of typecast doesn't work in C++ unless you use dynamic_cast or another RTTI system (like COM). dynamic_cast only works on classes with a vtable. Many C++ projects don't use any form of RTTI. (Note that the Go code does not assert that the Reader is a ReadClose; rather it depends on RTTI to determine whether the reader is a ReadClose.)
Also, used normally, the best you're going to get out of Data.Typeable is cast :: a -> Maybe b which means that if your two types don't have runtime equivalence you'll be handled a statically ensured runtime Nothing that you must handle gracefully. The semantics are extremely clean.
dynamic_cast only works on classes with a vtable
This isn't technically true - theoretically, you could implement C++ without vtables whatsoever. Furthermore, you could use a static_cast if the pointer had originally been cast from something lower down the hierarchy.
dynamic_cast downcasts in C++ only work across public inheritance. In particular a object that inheritance a Closable interface privately and a Reader interface publicly wouldn't allow a cross cast.
dynamic_cast isn't a loophole in the type system, it's there to strengthen it.
Usually private inheritance is mostly used for library code, as a way for code reuse but without exposing the inheritance relationship to the class users. Also coupled with mixins sometimes.
It's arguably true in a certainly commonly-used subset of C++ as well: this type of typecast doesn't work in C++ unless you use dynamic_cast or another RTTI system (like COM). dynamic_cast only works on classes with a vtable.
It's true that RTTI isn't used very much in C++, but I can't think of any non-trivial C++ project that doesn't include some traditional unsafe typecasts. And I have worked on a lot of C++ projects. And then there's the implicit type coercions, and the implicit constructors... ah, the good old days.
Haskell too, unless you explicitly opt in with Data.Typeable.
It's arguably true in a certainly commonly-used subset of C++ as well: this type of typecast doesn't work in C++ unless you use dynamic_cast or another RTTI system (like COM). dynamic_cast only works on classes with a vtable. Many C++ projects don't use any form of RTTI. (Note that the Go code does not assert that the Reader is a ReadClose; rather it depends on RTTI to determine whether the reader is a ReadClose.)