2 ms·
Requiring an explicit cast helps prevent type errors. It allows us to create types that mean something different than the original type. Consider a language wit
by throwaway894345 6y ago
Requiring an explicit cast helps prevent type errors. It allows us to create types that mean something different than the original type. Consider a language with a “bytestring” type which is just any sequence of binary data and another “string” type which can only be valid utf8. The two types are compatible as far as the compiler is concerned. If the compiler could automatically cast between these types, we would find bugs from non-utf8 bytestrings passed into functions expecting utf8 strings.