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
3answers
178 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, ...
9
votes
6answers
841 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 ...
-1
votes
1answer
53 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 ...
0
votes
1answer
53 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 ...
1
vote
0answers
49 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 ...
2
votes
2answers
448 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 ...
0
votes
1answer
93 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
214 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
106 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 ...
6
votes
3answers
503 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
98 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
162 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
110 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
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[...
1
vote
1answer
104 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
44 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
254 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
753 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 ...
58
votes
16answers
12k 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
312 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
90 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
71 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 ...
1
vote
2answers
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 [...
3
votes
2answers
485 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
789 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
353 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
537 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
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 ...
2
votes
1answer
159 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
309 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
47k 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
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-...
3
votes
1answer
193 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 ...
38
votes
8answers
11k 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 ...
18
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
367 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
106 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
372 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
83 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
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 ...
10
votes
3answers
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 ...
7
votes
2answers
174 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
467 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 ...
52
votes
3answers
10k 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
500 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
141 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 ...