Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [type-systems]

a type system is a collection of rules that assign a property called a type to the various constructs—such as variables, expressions, functions or modules— that a computer program is composed of.

Filter by
Sorted by
Tagged with
1 vote
1 answer
285 views

Is there a name for this API/type design principle? (I think of it as "state hygiene")

When designing types and their APIs, I try to adhere to these simple principles (which vaguely feel like one general principle to me) as much as feasible: There is a one-to-one correspondence between ...
suushikijitsu's user avatar
1 vote
5 answers
538 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...
AcinonX's user avatar
  • 613
-1 votes
1 answer
112 views

Finding intermediate type for conversion

After reading the whole question, you might think why I even need this, but believe me, it has a crucial usage in my project, which is very broad and complex, so I will only include the things ...
Aries Victor's user avatar
1 vote
7 answers
364 views

Is it possible to introduce Pointers to a weakly typed programming language?

Most weakly typed languages do not have a concept of a pointer. Instead, most of them use references. However, is it possible to introduce pointers to such a language. From a naive point of view, to ...
Lily White's user avatar
4 votes
3 answers
518 views

Is there a programming language other than Java, C#, and Go which includes null with its static object types?

I was reading the excellent book by Axel Raushmayer, Tackling TypeScript. In this section of Chapter 7, the author makes the interesting claim In many programming languages, null is part of all ...
Ray Toal's user avatar
  • 1,315
2 votes
3 answers
445 views

Best way to prevent people going overboard with Typescript?

I like typescript, and I want to add it to some projects in the company. Thing is, it is rather powerful, probably too powerful for it's own good at times. From experience, it doesn't take long until ...
user avatar
0 votes
0 answers
117 views

Python Typechecking versus TypedDicts?

From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function: def some_func(some_int: int, some_dict:...
a.t.'s user avatar
  • 225
3 votes
5 answers
433 views

Converting Dynamic Typing To Static Programatically

See: Type inference with duck typing - does this work? Why is it not used? And: General approach for proving decidability/undecidability Hello, I wanted to ask a theoretical question about type system ...
SeriousBusiness100's user avatar
1 vote
0 answers
58 views

Haskell: Data Modeling an Internal App that Interfaces with a 3rd-Party Library?

I wrote a java call graph generator with tree sitter (the 3rd-party library in question)'s python binding. I am doing a thought experiment on how I might model the same application in Haskell. I am ...
Acy's user avatar
  • 111
2 votes
1 answer
317 views

Best way to type-differentiate a Point and Vector?

I'm writing a ray-tracer in C++, and while writing a constructor for the Ray class: class Ray { public: Ray(const glm::vec3& origin, const glm::vec3& direction) : o{origin}, d{direction} {} ...
SRSR333's user avatar
  • 325
4 votes
3 answers
1k views

What is the relationship between variance, generic interfaces, and input/output?

There is a blog post by Eric Lippert where he describes how to define variance. In a general sense, covariance is achieved when the direction of assignment compatibility is preserved. Contravariance ...
Ramza's user avatar
  • 51
3 votes
1 answer
297 views

Disambiguating Python terms, what is the difference between "type hint" vs "type annotations"?

Colloquially, type hint and annotations are used interchangeably in Python. After reading PEP 484, I was unable to disambiguate the terms "type hint" vs "type annotations" from the ...
Keto's user avatar
  • 148
2 votes
3 answers
228 views

Strictly-Typed-Languages: “New”-Design Pattern?

I am writing extensively in a typed language in the last couple of months and wondering what a proper pattern for this behaviour is: When I create a new database entry (whatever this is) I am ...
ohboy21's user avatar
  • 172
1 vote
2 answers
329 views

Is it a good practice to allocate memory size to data types?

I'm learning rust and curious to know the purpose that we can allocate memory sizes to data types. I'm not clear yet how this could be an advantage. It can definitely save up some memory space but I ...
Lionel's user avatar
  • 19
0 votes
1 answer
139 views

Parsing complex data type names

How do compilers parse complex data types names like function pointers. The type has to be somehow put into the AST or it has to be processed during parsing. What are the pros and cons of different ...
Wojak2121's user avatar
1 vote
1 answer
2k views

Type-hinting and accessing values that are not initialized in __init__ (Python)

Suppose I have an instance attribute that I don't initialize in __init__, but in normal use it should be initialized before any other methods use the value. I want to structure everything so that it ...
nullUser's user avatar
  • 129
2 votes
3 answers
249 views

Where is the boundary between things which can be statically typechecked, and those which must be typechecked dynamically?

I am brain storming on how to create a type system for a programming language, and what the compiler will do with the typing information. Here is what I have found, followed by the main question, ...
Lance's user avatar
  • 2,611
10 votes
6 answers
2k views

Do any programming languages use types as values? Would there be any point?

The standard way that types are handled in programming languages that have such a concept, is that they are: removed entirely at compile time and are just used to determine memory layout, function ...
AIWalker's user avatar
  • 1,307
-1 votes
1 answer
84 views

Appropriate base type for simply typed lambda calculus

Given the following hypothetical programming language: Intended for practical programming A simply typed lambda calculus (STLC) All objects are functions, based on Church encodings I am aware that ...
Ari Fordsham's user avatar
2 votes
2 answers
441 views

What are the problems of subtyping?

I've heard often that Subtyping breaks some important and useful properties: many nice innovations developed by pure programming language researchers can't be brought to Java or C++ because of ...
Helloer's user avatar
  • 273
2 votes
0 answers
528 views

Using ftype to Declare Functions in Common Lisp

The Common Lisp Cookbook discusses how to use ftype to declare the inputs and outputs of functions. In compilers with a lot of type inferencing like SBCL, this would seem to offer a lot of support ...
davypough's user avatar
  • 137
3 votes
2 answers
2k views

How are dynamic and static typings implemented?

As I understand, every programming language is either statically type checked or dynamically type checked (and there are cases where these two approaches are mixed, but for simplicity I won't mention ...
RussoTuristo's user avatar
0 votes
1 answer
195 views

What are the benefits of not checking function arguments in python?

I'm trying to understand what are the benefits of the fact that python defaults to not checking function arguments. For example: from some_module import my_function my_function(some_argument) # ...
TheMeaningfulEngineer's user avatar
0 votes
2 answers
626 views

Liskov substitution principle: clarification about the "history rule"

I`m trying to understand the LSP History rule. I have read Wikipedia entry which states the requirement and provides an example: History constraint (the "history rule"). Objects are regarded as ...
MarcinG's user avatar
  • 141
1 vote
1 answer
200 views

How to avoid code duplication from handling "structually similar types" in Scala?

Often, when programming, you'll have different degrees of information to you in different contexts. For example, a web server may have two routes, which recieve information about a Person, one of ...
Joe's user avatar
  • 174
11 votes
3 answers
2k views

Naming of union and intersection types in TypeScript

In TypeScript, the following is called a union type: number | string and this is called an intersection type: number & string However, is the resulting type of the | not actually an intersection,...
P Varga's user avatar
  • 329
0 votes
1 answer
300 views

What's the name of the technique of using very specific types to help catch errors?

By way of background, I recently coded a small app that detects the number of boxes in an image. The app defines some types, for example: class Box(val x1: Int, val y1: Int, val x2: Int, val y2: Int) ...
paj28's user avatar
  • 1,653
3 votes
2 answers
751 views

Should entities have nullable id because they're autoganerated by the database?

Suppose I have a domain entity representing a person. (Examples in TypeScript) class Person { constructor(public name: string) {} } Now, because other parts of the domain will need to reference ...
villasv's user avatar
  • 147
1 vote
0 answers
127 views

What to do about compilation errors if ignoring them makes the app run fine?

Updating the libraries in my Angular 8/Electron app produced compilations errors eg, in Electron's menu.ts file, Also, a few of the project external libraries contain @ts-ignore lines, suppressing ...
schrödingcöder's user avatar
8 votes
4 answers
5k views

Is there a practical use for dependent types?

I've been reading about this thing called dependent types. So for example imagine a function firstNPrimes(int n) which returns an array of length n. In other words the type it returned would be int[...
zooby's user avatar
  • 253
1 vote
1 answer
809 views

When is it a good idea to include explicit type declarations in Kotlin?

In Kotlin, specifying the return types of functions and the types of variables is usually optional but can be optionally included. I've encountered a few benefits of including them: It sometimes ...
fluidj's user avatar
  • 147
1 vote
0 answers
49 views

What is the advantage to inferred types *in Swift*? [duplicate]

As I fool around in Swift I have come to absolutely hate variable declarations. int c = 0 seems easier to read than var c:Int = 0 and more informative than var c = 0, and int some() is radically ...
Maury Markowitz's user avatar
7 votes
3 answers
426 views

Is checking for unexpected types in dynamic languages in an untyped project necessary?

In statically typed languages or dynamically typed languages that use a type checking system you can guarantee that the input type is the type that you specified in the contract. However, in ...
Adam Thompson's user avatar
0 votes
1 answer
1k views

Difference between a strongly typed language and a weakly typed language with type annotations from the developer's point of view?

I understand that there are major technical differences between how a strongly typed language is compiled and how a type annotated language is compiled/transpiled. But as a developer writing in a ...
user1283776's user avatar
58 votes
16 answers
15k views

How should I store "unknown" and "missing" values in a variable, while still retaining the difference between "unknown" and "missing"?

Consider this an "academic" question. I have been wondering about about avoiding NULLs from time to time and this is an example where I can't come up with a satisfactory solution. Let's assume I ...
exhuma's user avatar
  • 1,191
1 vote
2 answers
410 views

Best practice regarding interfaces between "typed" and untyped" languages?

Our frontend JavaScript / Vue code makes uses of a number of "internal" REST endpoints, which are implemented in Java using Jersey/jax-rs. We have an "informal" specification that lists the ...
GhostCat's user avatar
  • 567
-1 votes
1 answer
95 views

How to develop larger client-site in-browser apps in javascript?

I'm new to javascript environment (I have background in C++ physical simulations and game engines). With rise of HTML5 and WebGL I was thinking I'd like to try make some games/3D editors using ...
Prokop Hapala's user avatar
0 votes
1 answer
118 views

Implicit conversion for function subtyping

Languages with coercions (i.e. implicit type conversions) allows expressing things like that (irrespective of any syntax): f : int32 → int32 = λx.x+x a : int16 = 42 b : int64 = f(a) Where type ...
cuihtlauac's user avatar
1 vote
2 answers
3k views

What exactly is a P-type software

I find this concept hard to understand. So in what situations we have solutions that are impractical or impossible like those P-systems try to implement? P-systems are described as: P-type [...
chris's user avatar
  • 251
3 votes
2 answers
807 views

Representing a structure/tuple type with Hindley Milner Type Inference

I'm writing a really simple interpreted object oriented programming language with a C-like syntax. I've been looking into type inference and I've found a few implementations of the 'Hindley-Milner ...
NegativeBreakfast's user avatar
4 votes
2 answers
960 views

Argument contravariance, real world purpose and usage?

I have read a few questions on the SO and elsewhere and still do not understand well where this "widening" of a parameter type can be helpful, i.e. compliying to Liskov substitution principle. The ...
John V's user avatar
  • 4,938
4 votes
3 answers
493 views

Liskov substitution for voids and weakened preconditions

I am learning a lot about this principle (also thanks to two answers I received here) and would like to elaborate on another point that somebody mentioned. 1) Is the following a violation of LSP? ...
John V's user avatar
  • 4,938
11 votes
4 answers
650 views

How exactly does a compiler recover from a type error?

I've read several papers, articles, and section 4.1.4, chapter 4 of Compilers: Principles, Techniques, and Tools (2nd Edition) (a.k.a "The Dragon Book") which all discuss the topic of syntactical ...
Chris's user avatar
  • 2,840
1 vote
0 answers
118 views

Can machine learning be used for non-numerical prediction?

I've started reading a machine learning book since a few days ago, and I've learned about how it can be used for classification/regression/etc. However, I am unsure if it will be able to handle the ...
James Ko's user avatar
  • 358
3 votes
1 answer
191 views

What is the term for different types that contain the same information?

What is the correct term(s) for different types that contain exactly the same information? For example (F#): type Type1 = (int * string) type Type2 = (string * int) When describing that these types ...
cmeeren's user avatar
  • 329
0 votes
1 answer
401 views

TypeScript - Can "Structural typing" and "OOP paradigm" co-exist?

From Type Compatibility - Introduction: Structural typing is a way of relating types based solely on their members. This is in contrast with nominal typing. Consider the following code: ...
user1787812's user avatar
21 votes
9 answers
79k views

Should one test the values of an enum using unit tests?

If you have an enum with values only (no methods as one could do in Java), and this enum is part of the business definition of the system, should one write unit tests for it? I was thinking that they ...
IS1_SO's user avatar
  • 347
1 vote
2 answers
90 views

Why 'Package' type does not inherit 'AccessibleObject' type?

Below are the relevant types(in java) for annotation processing, In addition to Field & Method types, Package type is also used in context of annotations with reflection, because these types ...
user1787812's user avatar
30 votes
6 answers
6k views

What is the common procedure used when compilers statically type check "complex" expressions?

Note: When I used "complex" in the title, I mean that the expression has many operators and operands. Not that the expression itself is complex. I've recently been working on a simple compiler to x86-...
Chris's user avatar
  • 2,840
3 votes
1 answer
198 views

Efficient algorithm for deducing object type dynamically based on members

I am designing a DSL (in clojure, specifically; though this question is more general than that) in which 'entities' are tracked as immutable hashes/maps, and where the 'concept' membership of an ...
nben's user avatar
  • 345