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
3 votes
1 answer
287 views

Why is type-punning at compile-time a no-go?

More on the topic of type-punning being problematic: C23 added constexpr and new rules as to how compile-time constants can be created and handled. We can now ...
CPlus's user avatar
  • 7,861
-4 votes
3 answers
155 views

Alternative names for a value that can either be true or false? [closed]

I know most languages use 'bool' or 'boolean' but I do not really like that name seeing as it was named after a person and a highly doubt that person invented the idea of yes or no questions ...
user1345541's user avatar
1 vote
2 answers
273 views

What is the mathematical abstraction of bitflags for use in a purely functional language?

A lot of C APIs like to have something called bit flags to signal the functions configuration options like Vulkan, OpenCL, SQLite and much more, it a typical pattern to it. This common pattern of ...
Delfin's user avatar
  • 159
5 votes
1 answer
305 views

Can final and full lattice type theory be combined?

Let us assume a language that has final with Java semantics, i.e. a final type cannot have subtypes. Further, let that language have a full lattice type theory with at least one bottom type, e.g. ...
feldentm's user avatar
  • 1,759
-1 votes
2 answers
167 views

Single-byte ASCII string as extension in an implementation of JavaScript [closed]

I'm planning for an implementation of JavaScript. This implementation will provide a memory-safe idiom-rich programming environment with focus on system-programming related goals, and will have a ...
DannyNiu's user avatar
  • 229
4 votes
4 answers
487 views

What programming languages contain a built-in imaginary data type?

Many languages like R, Julia, and Python store imaginary numbers as a complex number with a 0 valued real component. We may see this with the following R code: ...
Adam Hyland's user avatar
6 votes
1 answer
331 views

How to design interfaces to mimic haskell-like type classes in an object oriented language?

A problem I sometimes run into when using a language like TypeScript or C# is how they lack a perfect analogue to Haskell's typeclasses. Let's use Haskell's Functor ...
Kilian Kilmister's user avatar
21 votes
2 answers
4k views

To box or not to box? (how to determine if a value can be more efficiently passed by value or by reference)

I want to remove explicit addressing from my type system. In low level languages like C or Rust, you always have a choice whether to store some data by value or by reference. There are some advantages ...
mousetail's user avatar
  • 8,199
9 votes
3 answers
586 views

What does it mean for a type system or language to be "sound"?

Type systems and programming languages are sometimes described as being sound, or unsound, or sometimes just "not sound". What does being sound actually imply about them? Is it always the ...
Michael Homer's user avatar
  • 12.1k
4 votes
1 answer
304 views

Determining the most optimized data 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
  • 173
1 vote
1 answer
124 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
11 votes
1 answer
482 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
  • 3,065
9 votes
1 answer
340 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
  • 2,335
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,599
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 ...
CPlus's user avatar
  • 7,861
6 votes
1 answer
247 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
  • 12.1k
8 votes
3 answers
465 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
  • 231
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
  • 12.1k
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
  • 18.4k
19 votes
4 answers
3k 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
275 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
142 votes
1 answer
46k 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
  • 8,356
14 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
390 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,370
18 votes
4 answers
3k 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,833
3 votes
4 answers
1k 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). ...
чистов_n - за Россию's user avatar
12 votes
8 answers
3k 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 ...
CPlus's user avatar
  • 7,861
27 votes
8 answers
6k 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,643
8 votes
1 answer
344 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
137 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
  • 695
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
  • 695
5 votes
3 answers
262 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
  • 695
9 votes
5 answers
2k 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
26 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
  • 18.4k
6 votes
4 answers
282 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
  • 919
-2 votes
1 answer
179 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,833
7 votes
5 answers
283 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
  • 3,065
5 votes
4 answers
415 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,763
11 votes
3 answers
297 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
  • 12.1k
6 votes
2 answers
355 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 ...
CPlus's user avatar
  • 7,861
7 votes
1 answer
271 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 ...
CPlus's user avatar
  • 7,861
4 votes
3 answers
157 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
  • 8,199
7 votes
1 answer
2k 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
  • 12.1k
11 votes
1 answer
424 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
  • 12.1k
5 votes
3 answers
256 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 ...
CPlus's user avatar
  • 7,861
10 votes
1 answer
183 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
183 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
  • 12.1k
10 votes
1 answer
196 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
  • 18.4k
7 votes
2 answers
232 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 ...
CPlus's user avatar
  • 7,861
1 vote
2 answers
167 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,775