2022 Developer Survey is open! Take survey.

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
2 votes
3 answers
212 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 ...
user avatar
  • 172
1 vote
2 answers
220 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 ...
user avatar
  • 19
0 votes
1 answer
70 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 ...
user avatar
1 vote
1 answer
320 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 ...
user avatar
  • 121
2 votes
3 answers
216 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, ...
user avatar
  • 2,412
9 votes
6 answers
984 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 ...
user avatar
  • 1,187
-1 votes
1 answer
66 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 ...
user avatar
0 votes
1 answer
127 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 ...
user avatar
  • 233
1 vote
0 answers
159 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 ...
user avatar
  • 127
3 votes
2 answers
813 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 ...
user avatar
0 votes
1 answer
108 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) # ...
user avatar
0 votes
2 answers
323 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 ...
user avatar
  • 141
1 vote
1 answer
159 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 ...
user avatar
  • 174
8 votes
3 answers
1k 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,...
user avatar
  • 299
0 votes
1 answer
106 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) ...
user avatar
  • 1,663
3 votes
2 answers
178 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 ...
user avatar
  • 147
1 vote
0 answers
118 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 ...
user avatar
8 votes
3 answers
4k 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[...
user avatar
  • 253
1 vote
1 answer
249 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 ...
user avatar
  • 147
1 vote
0 answers
47 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 ...
user avatar
7 votes
3 answers
330 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 ...
user avatar
0 votes
1 answer
894 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 ...
user avatar
58 votes
16 answers
13k 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 ...
user avatar
  • 1,191
1 vote
2 answers
343 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 ...
user avatar
  • 542
-1 votes
1 answer
93 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 ...
user avatar
0 votes
1 answer
85 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 ...
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 [...
user avatar
  • 251
3 votes
2 answers
581 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 ...
user avatar
4 votes
2 answers
871 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 ...
user avatar
  • 4,878
4 votes
3 answers
413 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? ...
user avatar
  • 4,878
10 votes
4 answers
566 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 ...
user avatar
1 vote
0 answers
109 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 ...
user avatar
  • 358
2 votes
1 answer
179 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 ...
user avatar
  • 309
0 votes
1 answer
347 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: ...
user avatar
20 votes
9 answers
60k 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 ...
user avatar
  • 337
1 vote
2 answers
82 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 ...
user avatar
28 votes
6 answers
5k 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-...
user avatar
3 votes
1 answer
196 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 ...
user avatar
  • 316
38 votes
8 answers
13k 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 ...
user avatar
  • 836
4 votes
5 answers
1k 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 ...
user avatar
18 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 ...
user avatar
  • 289
4 votes
1 answer
411 views

What are some practical uses of Generalized Algebraic Datatypes? [closed]

All tutorials on GADTs that I've seen (in Haskell, Coq and Idris) use one same exapmle of a well-typed interpreter to show how GADTs can be useful, where you use the type index to encode the type of ...
user avatar
  • 284
-1 votes
2 answers
108 views

Are there good habits that can mitigate conflation of list structure types in practice?

I'll start by explaining what I mean in particular. Background In Javascript, arrays do it all (more or less a Lispy trait). Not only can you initialize, push, and pop, but you can also iterate, ...
user avatar
-1 votes
1 answer
448 views

GO - How to define methods of named type?

In GO, rule is, methods can be defined only on named type and pointer to named type. In C, below code, operations are defined on type(say List), typedef struct List List; //list.h typedef struct { ...
user avatar
  • 2,225
-2 votes
2 answers
84 views

Generic Type System [closed]

I am looking to an IoT like system which must deal with a wide range of data complexities. As an example, I'd like to model a 'thing' and I know all things have a location. However, when the actual ...
user avatar
6 votes
2 answers
142 views

Can we have implicitly typed members?

Implicit typing in languages like C# permits compile-time type checks without necessarily referring "directly" to a target class: var toy = SantasWorkshop.Build(); toy.amuse(); In this scenario, we ...
user avatar
  • 13.2k
10 votes
3 answers
2k views

What is the difference between Haskell's type classes and Go's interfaces?

I am wondering if there is a difference between Haskell's type classes and Go's interfaces. Both define types based on functions, in that way, that a value matches a type, if a function required by ...
user avatar
  • 343
7 votes
2 answers
196 views

Are lower-arity functions subtypes of higher-arity ones?

I've found that there isn't a concept similar to "arity-based subtyping" in many languages that I've programmed in, where higher-order functions could consume functions of lower arity than their ...
user avatar
  • 497
3 votes
1 answer
493 views

Are there only 2 places you can declare new generic type parameters in Java?

It's confusing because type declaration and usage both use the <T> syntax. I think there are only 2 places where you can declare new generic types in Java: 1. In the definition of a class or ...
user avatar
  • 14.5k
53 votes
3 answers
11k views

What is a type system?

Background I am designing a language, as a side project. I have a working assembler, static analyser, and virtual machine for it. Since I can already compile and run non-trivial programs using the ...
user avatar
  • 2,255