2

If interpreted languages have their source code translated at run-time and statically typed languages have their types assigned at compile time how can a language be both?

From this question I understand that is is possible: Which languages are dynamically typed and compiled (and which are statically typed and interpreted)?

This page explains quite well the distinction between statically typed and dynamically typed languages:https://hackernoon.com/i-finally-understand-static-vs-dynamic-typing-and-you-will-too-ad0c2bd0acc7

I just don't understand how a language can be both statically typed and interpreted?

Thanks

Simon
  • 107
  • 2
  • 10

1 Answers1

2

Interpreted does not mean that each line of the source code is parsed right before that line is executed. There is typically an initialization step where the interpreter parses the entire program before it starts executing it. At that point, the interpreter could apply type checks.

As a practical example of this, mypy is a Python type checker that can be used to check Python type annotations before running the code.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • Is this correct? `mypy` is not a Python interpreter, you cannot run code via `mypy` as far as I am aware. Can you provide evidence of this? `mypy` is an external tool that does type-checking whenever you run it. For example when developing locally or in CI pipelines. But its misleading to say this is 'before execution begins' no? – Tim O'Sullivan Apr 13 '22 at 11:47
  • I guess I was misinformed, fixed. – Thomas Apr 13 '22 at 14:06