Questions tagged [static-typing]
For questions relating to languages whose variables' data types are known at compile time, and type systems supporting this.
21
questions
26
votes
6
answers
1k
views
Why don't many languages have integer range types?
An integer range type like 0..100 means that a value can be any integer in that range. Arithmetic operations on range types produce other range types, for example ...
19
votes
4
answers
3k
views
To what extent is type theory relevant to dynamically typed languages?
There seem to be two conflicting views regarding the status of "type systems" used in dynamically typed languages:
That dynamically typed languages are actually just unityped static ...
15
votes
6
answers
5k
views
"Testing" that something does not compile in metaprogramming
Use case
Some languages offer techniques to ensure certain requirements at compile time. For example, rust has the NonZeroU32 type that will ensure at compile time ...
15
votes
1
answer
513
views
What are some options for integrating subtyping with Damas-Hindley-Milner inference?
Type inference in a Damas-Hindley-Milner type system with subtyping is known to be undecidable in general.
What makes it so difficult? What options are there to get around undecidability which could ...
13
votes
5
answers
409
views
What strategies did Go use to circumvent the lack of generics?
Go (was) famous for its lack of generics. However, the lack of generics in a statically typed language makes quite a few things harder. For example (in a pseudocode because I don't know Go):
...
12
votes
4
answers
1k
views
Why does Python ignore type hints?
In Python, everything is treated as an object. This means that CPython interpreter will decide on the fly, what is the type of each variables or the function return type depending on the current state....
11
votes
3
answers
316
views
How can a language statically ensure a required index exists in a list?
Suppose a language has a conventional list data structure that contains some dynamic number of values indexed sequentially. Some operations to access a value from the list require that a certain index ...
11
votes
2
answers
341
views
What are the run-time implications of gradual typing?
Statically-typed languages specify the types of variables and functions and reject programs they know won't work before they run. Dynamically-typed languages don't include these annotations or checks, ...
11
votes
1
answer
444
views
How can I have mutually-exclusive properties in a structural type system?
I have a structurally-typed object-oriented language, and I'd like to allow for types with some mutually-exclusive properties/attributes/slots/methods. That is, an object having more than one of these ...
10
votes
1
answer
207
views
How can optional properties be made sound in a static structural type system?
Typescript's structural type system is known to be (intentionally) unsound, in the sense that the value of an expression at runtime is not always necessarily assignable to its type determined at ...
9
votes
5
answers
1k
views
How to make logical operators that return operands consistent in a statically typed language?
In C++, 3 || 4 returns true. But in Python, 3 or 4 returns 3 instead. That's a logical operator that returns its operand. I don'...
9
votes
4
answers
634
views
What are the pros and cons of static typing?
Static typing means the type of a variable is known at compile time. This means that either you have to specify the type, or the compiler has to infer it (usually both). You also can't change the type ...
9
votes
1
answer
2k
views
Is Epic Games' Verse gradually typed?
I've just watched an interview on YouTube with Simon Peyton Jones where they talk about Epic's Verse language. Here (at roughly 51:30) they start talking about the type system.
Simon mentions that ...
8
votes
1
answer
366
views
How, if at all, do kinds fit into the type universe hierarchy?
As I understand it, as a (value-level) function f that takes a value x of type T and returns ...
7
votes
2
answers
304
views
How to Add Static Typing to a Stack Language?
What level of static typing can be added to a stack-based language? I know it's impossible to fully statically type some stack languages:
...