Questions tagged [types]

For questions about types, which are different forms of data that can be stored in a variable, such as strings, numbers, or arrays.

Filter by
Sorted by
Tagged with
4 votes
0 answers
117 views

Determining the most optimized date type for the platform with type inference

For my programming language, I have built an engine that goes after the parser and before the compiler. This engine analyzes, validates, and simplifies the AST. During the analasys, it determines as ...
Hg0428's user avatar
  • 171
1 vote
1 answer
109 views

Expressing runtime constraints with trait-bounds

I've recently listened to Corecursive episode with John A De Goes and there's one thing that really got me thinking: the idea of type class laws pertaining to performance guarantees. The example ...
gstukelj's user avatar
  • 143
9 votes
1 answer
221 views

What is the difference between GAT and HKT?

I implemented a basic generics-free, parameterless trait (type class) system. And I want to parameterize my trait system. The alternative paths I know of are Generic Associated Types (GAT) and Higher-...
Aster's user avatar
  • 2,552
9 votes
1 answer
321 views

Why does ATTAPL's linear product introduction rule not delete the objects from the context?

In Chapter 1 of Advanced Topics in Types and Programming Languages, the following rule is presented for the introduction of a product in a linear/unrestricted type system: ($\circ$ is context ...
blueberry's user avatar
  • 1,582
12 votes
7 answers
4k views

Are there any situations in which it would make sense to return a never type?

Some languages (Rust is the first one that comes to mind) have a "never" type. This is represented in Rust as !, and represents a function that never ...
Ginger's user avatar
  • 2,451
17 votes
3 answers
2k views

What optimizations does the strict aliasing rule facilitate?

This question is tangentially related to: Why is type reinterpretation considered highly problematic in many programming languages? Regardless how 'problematic' type reinterpretation is, why do some ...
user16217248's user avatar
  • 7,245
6 votes
1 answer
232 views

How do you implement a structural subtyping checker?

In a structurally-typed language, one type is a subtype of another iff it has all of the fields/methods of the other with compatible types, meaning that field or return types are subtypes, parameter ...
Michael Homer's user avatar
  • 10.8k
7 votes
3 answers
333 views

How to incorporate sum types into SQL?

The blog post states that a major drawback of SQL is its lack of sum type support. Assuming we could redesign SQL today (without necessarily having to worry about compatibility) what are some specific ...
Jw C's user avatar
  • 121
9 votes
1 answer
2k views

Why can you implement a Monoid type in Java or C#, but not Monad or Functor?

Haskell and some other functional languages have Monad and Monoid types (and Semigroup, Functor, Applicative, and many others), and lists, trees, Maybe, and other types subtype all or some of these. ...
Michael Homer's user avatar
  • 10.8k
11 votes
4 answers
1k views

How can type systems be a useful formal framework for modeling things other than type-checking?

Quoting one of Alexis King's answers: Many programming language researchers would call many things “type systems” that programmers probably don’t think of as type systems. Many forms of static ...
kaya3's user avatar
  • 16.3k
19 votes
4 answers
2k views

To what extent is type theory relevant to dynamically typed languages?

There seem to be two conflicting views regarding the status of "type systems" used in dynamically typed languages: That dynamically typed languages are actually just unityped static ...
Caleb Thomas's user avatar
6 votes
1 answer
259 views

How to give a type to a continuation that is polymorphic in the parameter?

I was trying to implement algebraic effects in my language, but I was caught into the same problem that some papers about CPS try to solve in a expression like ...
Sofia Rodrigues's user avatar
138 votes
1 answer
44k views

How should I read type system notation?

I sometimes read articles or papers about type systems that use some funny-looking, two-dimensional notation with lots of unfamiliar symbols and Greek letters. The notation seems mathematical, but it’...
Alexis King's user avatar
  • 7,779
13 votes
10 answers
4k views

Are there any practical use cases for subtyping primitive types?

In, for example, Python, it is possible to subtype primitive types: ...
Wheelwright's user avatar
3 votes
2 answers
345 views

What are the possible variations of the type of "this" or "self"?

In the class definitions of an object oriented language, this refers to the object instance the code is about to work upon. Naturally, it should have the same type ...
user23013's user avatar
  • 2,010
17 votes
4 answers
2k views

When do we need complex type inference?

Two of the most significant type inference schemes are Hindley-Milner and Bidirectional typing but when do we actually need do type inference? The simple case is something like: ...
Bruce Adams's user avatar
  • 2,733
3 votes
4 answers
738 views

What are pros and cons of tagged vs untagged union-types?

Some languages accept untagged union types (C++, C, etc): union Something { char ch; int i; }; Some languages accept tagged union types (like Haskell). ...
nchistov's user avatar
  • 1,521
12 votes
8 answers
2k views

What are the advantages of having a set number of fixed sized integers versus defining the exact number of bits in every integer?

In most statically typed languages, integers are offered in 8-bit types and increasing powers of 2. However, C has a new keyword _BitInt which as I understand ...
user16217248's user avatar
  • 7,245
26 votes
8 answers
5k views

What are the pros and cons of having a unit type over C-like void?

Unit types are types found in more modern languages, replacing void in the C-family languages. Unlike void, a unit type has an ...
Seggan's user avatar
  • 2,594
8 votes
1 answer
311 views

How, if at all, do kinds fit into the type universe hierarchy?

As I understand it, as a (value-level) function f that takes a value x of type T and returns ...
user570286's user avatar
4 votes
1 answer
121 views

How the compiler or runtime handles types which are complex patterns or have complex constraints?

Pattern Types I am coming from JS/Ruby-land, where in Rails you have things like validation that a string field on a data model matches the IP address regex, for example: ...
Lance's user avatar
  • 655
15 votes
5 answers
3k views

Do you need an "Any" type when implementing a statically typed programming language?

As per the comment about Swift having an Any type here (and my related question in that post, on how to access type metadata at runtime without increasing the ...
Lance's user avatar
  • 655
4 votes
3 answers
236 views

How to avoid output build bloat when wanting to access type metadata information at runtime?

In my answer to the question What are the advantages and disadvantages of making types as a first class value?, I point out that for the language I'm working on, I wanted to have the ability to do ...
Lance's user avatar
  • 655
8 votes
5 answers
1k views

What are the advantages and disadvantages of making types as a first class value?

Making them a "first-class value" means that instances of them can be returned from functions, passed into functions, or constructed at runtime, which I'd presume is useful. But, I would ...
Starship - On Strike's user avatar
25 votes
6 answers
1k views

Why don't many languages have integer range types?

An integer range type like 0..100 means that a value can be any integer in that range. Arithmetic operations on range types produce other range types, for example ...
kaya3's user avatar
  • 16.3k
4 votes
4 answers
250 views

How do languages handle bitwise flags?

In most languages, enum types intersect with number types, implicitly converting between them so you can do ...
Hydroper's user avatar
  • 749
-2 votes
1 answer
171 views

Why are type theorhetic data structures rarer (than sets) if they are fundamental? [closed]

Set theorhetical structures and operations are quite fundamental and typically are either part of a languages standard library or built into it. Given that types are fundamental to programming why do ...
Bruce Adams's user avatar
  • 2,733
7 votes
5 answers
240 views

Why intersection types have more fields and union types have fewer fields?

There's a question that's been bothering me. I even implemented it backwards when I implemented the type system for my language. Why do intersection types have more fields and union types have fewer ...
Aster's user avatar
  • 2,552
5 votes
4 answers
333 views

What are the differences between Unit and Singleton Types?

A Unit Type is one inhabited by exactly one value, and, due to the lack of possible discrimination ("no information able to be held"), is reducible to the 0-tuple. Meanwhile a Singleton is ...
Longinus's user avatar
  • 1,723
10 votes
3 answers
249 views

How can a language statically ensure a required index exists in a list?

Suppose a language has a conventional list data structure that contains some dynamic number of values indexed sequentially. Some operations to access a value from the list require that a certain index ...
Michael Homer's user avatar
  • 10.8k
6 votes
2 answers
271 views

If size could be determined at compile time then why could size not be determined at preprocess time?

In C the sizeof() operator cannot be resolved in preprocessor conditions. If other operators such as + or ...
user16217248's user avatar
  • 7,245
7 votes
1 answer
253 views

Why do many dynamically typed languages identify types with strings?

I noticed in JavaScript and Lua, 'types' i.e., those returned by typeof()/type() are just identified by strings. As such we see ...
user16217248's user avatar
  • 7,245
4 votes
3 answers
142 views

How to support contravariant generics in a structural type system?

In a structural type system, a interface is just a list of properties with types and anything that has those properties automatically implements the interface. Typescript is one such example but it is ...
mousetail's user avatar
  • 6,696
7 votes
1 answer
958 views

What design trade-offs led to the "Norway problem" in YAML, and when are they worthwhile?

A well-known problem in YAML is a type-inference issue in parsing where a string is misinterpreted as a boolean. This is known as the "Norway problem", because it occurs when a field or ...
Michael Homer's user avatar
  • 10.8k
11 votes
1 answer
371 views

How can I have mutually-exclusive properties in a structural type system?

I have a structurally-typed object-oriented language, and I'd like to allow for types with some mutually-exclusive properties/attributes/slots/methods. That is, an object having more than one of these ...
Michael Homer's user avatar
  • 10.8k
5 votes
3 answers
214 views

Types and variables in a different namespace

What would it take to design a language that permitted construct such as below? int int = 10; Such a language would need to be able to infer contextually whether a ...
user16217248's user avatar
  • 7,245
10 votes
1 answer
172 views

How is fixpoint of type exponentiation implemented?

Fixpoint of type addition or type multiplication is no big deal. You just need to store data in heap. Haskell does this well for lists for example: ...
Dannyu NDos's user avatar
11 votes
3 answers
169 views

How can a block-based language represent type-compatibility of blocks?

Block-based languages use individual "jigsaw puzzle" pieces of code that slot together to build up programs. Commonly the blocks have various obvious protrusions and depressions that make ...
Michael Homer's user avatar
  • 10.8k
10 votes
1 answer
153 views

How can optional properties be made sound in a static structural type system?

Typescript's structural type system is known to be (intentionally) unsound, in the sense that the value of an expression at runtime is not always necessarily assignable to its type determined at ...
kaya3's user avatar
  • 16.3k
7 votes
2 answers
212 views

Why short and long and double and similar instead of unambigous width types such as int16 or int64 or float64?

Many languages have keywords short and int and long and ...
user16217248's user avatar
  • 7,245
1 vote
2 answers
150 views

What are the pros and cons of having a unique type for generators?

For languages that allow generators (iterables where elements are determined by a function), what are the pros and cons of having a unique type for generators? For example, languages like python have ...
lyxal's user avatar
  • 1,747
4 votes
1 answer
95 views

How could a language implement generic traits?

Take C#'s IEnumerable<T> interface. It has a singular requirement: ...
Bbrk24's user avatar
  • 8,553
7 votes
1 answer
181 views

What are the advantages of using Dependent Modal Types in a language?

I was trying to read a paper called Implementing a Modal Dependent Type Theory that implements a type that causes the context to "lock" but I don't know how it would be useful outside of ...
Sofia Rodrigues's user avatar
10 votes
1 answer
133 views

What is a GADT skolem?

Long ago, I got an error message in Scala informing me that I had a GADT skolem. I googled but only found very abstract descriptions of GADT skolems, nothing with an example that illustrated in a ...
Ben Kovitz's user avatar
7 votes
3 answers
304 views

What are common approaches to representing types within a compiler?

I'm implementing my own statically-typed programming language and I'm not too happy with my own approach to types. At the moment, I'm relying on mapping a textual representation of a type to an index ...
springogeek's user avatar
8 votes
1 answer
81 views

How can it be determined that a cast or type test is unchecked?

In languages like Java that use type erasure for generics, some casts are considered unchecked. One example is casting a value of Object to ...
MI3Guy's user avatar
  • 181
2 votes
2 answers
139 views

What should a variable-size contiguous collection be called?

Different languages have different names for the same thing. Off the top of my head, there's: C++ vector and Rust Vec Java <...
Bbrk24's user avatar
  • 8,553
17 votes
8 answers
894 views

What are the advantages/disadvantages of prefix type syntax?

Famously, C’s functions and variables have their types specified before the function/variable name: bar foo() {...} bar foo = ...; Most older C derivatives also ...
Seggan's user avatar
  • 2,594
4 votes
2 answers
201 views

What are some disadvantages to allowing interfaces to require static members?

Swift allows protocols (called "interfaces" or "traits" in other languages) to require initializers and static members. This allows things like this: ...
Bbrk24's user avatar
  • 8,553
16 votes
1 answer
297 views

What are the pros and cons of eliminators vs. pattern matching with a termination checker?

In type theoretic presentations of programming languages, we usually define an elimination principle similar to a function for inductive types, and we assume pattern matchings to be elaborated into ...
ice1000's user avatar
  • 2,284