samedi 14 octobre 2017

What does a language need to be able to check types at runtime

So, I'm studying a new language right know and came across the issue to determine the type of a variable at runtime. Searching for a good way I read somewhere (unfortunately, I can't find the exact source again) that this is not possible because haskell does not support reflection. This was just a remark at the side in the article, not a satisfactory explanation and made we wonder:

What does a programming language actually need to be able to know the type of variables at runtime?

  • Is it at all possible to give a generic answer to this, or is it too dependent on the individual implementations of different languages.
  • Is reflection really required? (I kind of doubt it since C++ provides some methods runtime determine type for C++)
  • Is it a object-orientation thing or is this like comparing apples and oranges? (I wonder because it is mentioned in answers of some other questions.)
  • Am I missing a term that would yield answers to this question directly? (Maybe I just lack the correct terminology.)

My thoughts so far:

  • obviously the type information has to be stored "somewhere", that's why it is impossible to know a type at runtime in C (runtime determine type for C).
  • gut feeling tells me that statically typed languages might drop type information at compile time, after it has been checked -> information not available at runtime (Example: Haskell?)
  • vice versa, I would expect that dynamically typed languages need to store type information and support checking for types per definition.




Aucun commentaire:

Enregistrer un commentaire