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
0
votes
1answer
87 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) # ...
0
votes
2answers
157 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 ...
1
vote
1answer
101 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 ...
4
votes
3answers
209 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,...
0
votes
1answer
96 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) ...
3
votes
2answers
155 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 ...
1
vote
0answers
108 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 ...
7
votes
3answers
3k 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[...
1
vote
1answer
83 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 ...
1
vote
0answers
40 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 ...
5
votes
3answers
226 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 ...
0
votes
1answer
548 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 ...
57
votes
16answers
11k 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 ...
1
vote
2answers
295 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 ...
-1
votes
1answer
89 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 ...
0
votes
1answer
66 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 ...
2
votes
1answer
2k 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 [...
2
votes
2answers
427 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 ...
4
votes
2answers
712 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 ...
4
votes
3answers
314 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? ...
10
votes
4answers
513 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 ...
1
vote
0answers
107 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 ...
2
votes
1answer
143 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 ...
0
votes
1answer
281 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: ...
17
votes
9answers
40k 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 ...
1
vote
2answers
81 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 ...
24
votes
6answers
4k 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-...
3
votes
1answer
192 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 ...
35
votes
8answers
10k 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 ...
4
votes
5answers
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 ...
17
votes
3answers
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 ...
4
votes
1answer
332 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 ...
-1
votes
2answers
105 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, ...
-1
votes
1answer
313 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 { ...
-2
votes
2answers
82 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 ...
6
votes
2answers
141 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 ...
9
votes
3answers
1k 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 ...
7
votes
2answers
171 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 ...
3
votes
1answer
458 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 ...
51
votes
3answers
9k 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 ...
2
votes
3answers
441 views

Primitive types vs fundamental types?

I have heard both "fundamental types" and "primitive types" being used. Is there a difference in what the two phrases are referring to?
30
votes
9answers
4k views

Are there any design patterns that are possible only in dynamically typed languages like Python?

I've read a related question Are there any design patterns that are unnecessary in dynamic languages like Python? and remembered this quote on Wikiquote.org The wonderful thing about dynamic typing ...
53
votes
10answers
8k views

Why do mainstream strong static OOP languages prevent inheriting primitives?

Why is this OK and mostly expected: abstract type Shape { abstract number Area(); } concrete type Triangle : Shape { concrete number Area() { //... } } ...while this is not OK and ...
1
vote
1answer
134 views

What is the connection between type inference and advanced type systems?

I don't understand the connection between type inference and advanced type systems. I don't see why Haskell or Standard ML or OCaml could not have existed without type inference. My only guess is that ...
4
votes
3answers
236 views

Verbose Return Types

I've recently been writing some code that deals with 3rd parties -- obviously errors will happen so I'm using Either/Maybe monads where appropriate. As this is C# I'm also using async Tasks too. My ...
4
votes
2answers
139 views

Type of multi methods in a static object-functional language

I'm currently working on expanding the capabilities of my pet programming language project's type system, and have come across an interesting area where my research into other language's type systems ...
8
votes
1answer
803 views

Perform crossover operation on AST in genetic programming

So in general when you perform a crossover in GA, you directly flip a random section in the "genome", with the corresponding section in the other parent, and mutate it based on the mutation rate. ...
22
votes
1answer
3k views

Could Hindley-Milner inference work for the Go language?

I've read that Hindley-Milner does not work with type systems that have subclasses, and there are other type system features that also do not work well with it. Go currently has only very limited type ...
7
votes
1answer
214 views

Should an interface covariant on T ever implement an interface invariant on it?

I was reading through the Hacklang docs on Collections, and came across this curious definition [paraphrased slightly]: interface KeyedIterable<Tk, Tv> ... interface ConstVector<+Tv> ...
9
votes
1answer
3k views

What do banks actually use as a data type for money? [closed]

I'm aware of a few good options: Big integers (e.g., int64_t, mpz_t, any bignum lib) to represent cents or 10-n cents—say, an integer represents 1/100 of a penny ($1.05 == 10500). This is called a ...