Machine-translated by Google. Questions are authored in English.
Top

Discussion

A compiler for a language with no type declarations must

  • A.require the programmer to supply types on the command line
  • B.infer the types of expressions from their use in the program
  • C.abandon semantic analysis entirely for that language
  • D.treat every value as an integer for the purpose of code generation

Answer: B

Correct answer: infer the types of expressions from their use in the program

Absence of declarations does not mean absence of types. The compiler deduces them from how values are used - from literals, from the operators applied, and from the requirements of the functions a value is passed to.

Hindley-Milner inference is the classical algorithm, and ML and Haskell rest on it. Semantic analysis is certainly not abandoned; if anything it does more work, since it must reconstruct what a declaring language would simply have been told.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.