Re:What is type safety?
by tel on Tuesday August 05, 2014 @01:08PM
(#8138017)
Type casting has to be modeled (more or less) as (a) upcasting only (b) a failure of type safety, or (b) an admission that the type system is entirely vacuous.
[ Parent
| on HN ]
Re:What is type safety?
by AnimalMuppet on Tuesday August 05, 2014 @01:38PM
(#8138187)
No, you can have downcasting that is checked for validity at runtime, a la Java (or C++ with RTTI). This is not a failure of type safety, since only valid casts will be performed. It's not vacuous, either - it's not just one big type.
What happens when a cast is invalid?
You have type-safe casts in Haskell, for instance, where the failure is reflected at runtime.
cast :: (Typeable a, Typeable b) => a -> Maybe b
Those are alright.
Re:What is type safety?
by AnimalMuppet on Tuesday August 05, 2014 @03:24PM
(#8138798)
In Java, IIRC, the cast fails with a ClassCastException. That seems to me to be "failure is reflected at runtime".
In C++ with RTTI, IIRC it returns null. That's also "failure at runtime" (of a sort), but you have to check it.