3 ms·
Most static typed compiled languages also ignore types at runtime :)
by whimsicalism 5y ago
Most static typed compiled languages also ignore types at runtime :)
- munificent 5y agoNot true. Java, C#, Scala, Kotlin, Swift, Dart, and others all keep around type information at runtime so that casts can throw exceptions at runtime when the value isn't of the right type. Otherwise, soundness is lost. In practice, most modern statically typed languages maintain soundness through a combination of compile time and runtime checking.
- whimsicalism 5y ago> most modern statically typed languages maintain soundness through a combination of compile time and runtime checking. Rust, C, C++ - all do not keep around this information. You're right that the JVM languages (and thus, naturally, C#) do it differently. I think it is a bit silly to name out each of the JVM languages separately.
- pharmakom 5y agoC++ community is split by the RTTI compiler flags
- zozbot234 5y agoRust standard library includes RTTI support, though it's very rarely used.
- munificent 5y agoHaskell, Go, and I think OCaml also rely on some amount of runtime checking for soundness. I think basically every managed statically typed language ends up carrying around runtime representation and uses some amount of runtime checks.
- hither_shores 5y agoHaskell has full type erasure.
- munificent 5y agoIt still has to carry around enough information to detect non-exhaustive matches and throw at runtime, no?
- dllthomas 5y agoOnly in the same way that "if ... else if ... else" needs to know about types, which is to say mostly not. AFAIK - and this might be either dated or just wrong - the two places GHC doesn't fully erase are 1) polymorphic recursion (where if we squint it's probably not unreasonable to treat the dictionaries as type tags), and 2) when the programmer explicitly asks for run-time type information with Typeable.
- whimsicalism 5y agoBut what are you performing the "if else" on? Type level information stored at runtime, no?
- dllthomas 5y agoValue level information. The compiler statically knows the type that's being matched on. It's true that the generated code depends on the type, but that's not any more true than when a C compiler generates an integer comparison vs a float comparison in the conditional of that "if". All that's looked at at runtime is the data.
- tome 5y agoYes, but those aren't types, they're values.
- whimsicalism 5y ago