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
7 answers
335 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
3 votes
3 answers
292 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,305
1 vote
3 answers
347 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
108 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
411 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
232 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
  • 315
4 votes
3 answers
862 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
166 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
  • 149
2 votes
3 answers
224 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
300 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
94 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
1k 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
241 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,561
10 votes
6 answers
1k 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,287
-1 votes
1 answer
83 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
1 vote
1 answer
273 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
  • 253
2 votes
0 answers
392 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
1k 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
160 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
503 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
191 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
110 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,663
3 votes
2 answers
510 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
126 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
651 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
48 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
396 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
14k 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
391 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
  • 542
-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
110 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
719 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
933 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,908
4 votes
3 answers
479 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,908
10 votes
4 answers
619 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 ...
Christian Dean's user avatar
1 vote
0 answers
113 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
190 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
393 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
74k 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
86 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-...
Christian Dean's user avatar
3 votes
1 answer
197 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
38 votes
8 answers
15k views

Why exactly does Java not allow numeric conditionals like if(5) { ...} if C does?

I have these two little programs: C #include <stdio.h> int main() { if (5) { printf("true\n"); } else { printf("false\n"); } return 0; } Java class ...
toogley's user avatar
  • 846
4 votes
5 answers
2k views

Type inference with duck typing - does this work? Why is it not used?

Suppose we have a functional language where objects don't have explicitly defined types, but where named properties can nonetheless be accessed on objects. Is it then possible for the compiler to ...
Reinstate Monica's user avatar
19 votes
3 answers
3k views

How do the type systems in functional languages differ from those in OO languages? [duplicate]

I keep reading stories from developers who state that once they are able to get the FP programs written in languages like Haskell, Ocaml, Elm and even Rust, to compile without errors, they are pretty ...
vfclists's user avatar
  • 299