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.

learn more… | top users | synonyms (1)

51
votes
5answers
6k views

What can Haskell's type system do that Java's can't and vice versa?

I was talking to a friend about the differences between the type systems of Haskell and Java. He asked me what Haskell's could do that Java's couldn't, and I realized that I didn't know. After ...
48
votes
5answers
4k views

How do languages with Maybe types instead of nulls handle edge conditions?

Eric Lippert made a very interesting point in his discussion of why C# uses a null rather than a Maybe<T> type: Consistency of the type system is important; can we always know that a ...
46
votes
6answers
3k views

Dynamically vs Statically typed languages studies

Do there exist studies done on the effectiveness of statically vs dynamically typed languages? In particular: Measurements of programmer productivity Defect Rate Also including the effects of ...
41
votes
12answers
4k views

When is type testing OK?

Assuming a language with some inherent type safety (e.g., not JavaScript): Given a method that accepts a SuperType, we know that in most cases wherein we might be tempted to perform type testing to ...
40
votes
8answers
3k views

What are the safety benefits of a type system?

In JavaScript: The Good Parts by Douglas Crockford, he mentions in his inheritance chapter, The other benefit of classical inheritance is that it includes the specification of a system of types. ...
28
votes
12answers
3k views

Is Haskell's type system an obstacle to understanding functional programming?

I'm studying Haskell for the purpose of understanding functional programming, with the expectation that I'll apply the insight that I gain in other languages (Groovy, Python, JavaScript mainly.) I ...
26
votes
9answers
3k views

Do dynamic typed languages deserve all the criticism? [closed]

I have read a few articles on Internet about programming language choice in the enterprise. Recently many dynamic typed languages have been popular, i.e. Ruby, Python, PHP and Erlang. But many ...
23
votes
3answers
2k views

A good generic type system

It's commonly accepted that Java generics failed in some important ways. The combination of wildcards and bounds led to some seriously unreadable code. However, when I look at other languages, I ...
19
votes
4answers
4k views

Why does Java not do type inference?

I have always wondered why Java does not do type inference given that the language is what it is, and its VM is very mature. Google's Go is an example of a language with excellent type inference and ...
19
votes
9answers
22k views

Type Casting variables in PHP: Is there a practical example?

PHP, as most of us know, has weak typing. For those who don't, PHP.net says: PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined ...
19
votes
2answers
5k views

Type inference in Java 8

Is the introduction of the new lambda notation (see e.g. this article) in Java 8 going to require some kind of type inference? If so, how will the new type system impact the Java language as a whole? ...
18
votes
24answers
1k views

Interesting or unique types in programming languages? [closed]

We have all seen integer, floating point, string, and the occasional decimal type. What are some of the most strange or unique or useful types you have encountered, useful or not?
18
votes
5answers
2k views

Why is type inference useful?

I read code way more often than I write code, and I'm assuming that most of the programmers working on industrial software do this. The advantage of type inference I assume is less verbosity and less ...
18
votes
2answers
1k views

Type checking and recursive types (Writing the Y combinator in Haskell/Ocaml)

When explaining the Y combinator in the context of Haskell, it's usually noted that the straight-forward implementation won't type-check in Haskell because of its recursive type. For example, from ...
16
votes
5answers
1k views

Would it make sense to use objects (instead of primitive types) for everything in C++?

During a recent project I've been working on, I've had to use a lot of functions that kind of look like this: static bool getGPS(double plane_latitude, double plane_longitude, double plane_altitude, ...
16
votes
1answer
2k views

Motivation and pitfalls (?) of the auto keyword in C++11

I was recently wondering why the keyword auto was chosen in C++11 to mark a variable whose type must be inferred by the compiler, like in auto x = 1; Since var seems more common in other ...
16
votes
6answers
7k views

Is hungarian notation a workaround for languages with insufficiently-expressive (i.e. Haskell-style) static typing?

Edit To be clear, I'm not talking about annotation variable names with the data type, but rather with information about the meaning of the variable in the context of the program. For example, a ...
15
votes
5answers
4k views

What arguments are there in favor of weak typing?

This came up in a discussion with a friend, and I found myself hard-pressed to think up an any good arguments. What benefits do weak typing confer?
15
votes
6answers
508 views

Should all programmers learn at least one very-high-level language? [closed]

One mandatory course I took in uni was about functional and logical programming languages (Haskell and Prolog). It was mildly interesting, and most I talked to showed even less interest to the course ...
14
votes
10answers
4k views

Why are inheritance and polymorphism so widely used?

The more I learn about different programming paradigms, such as functional programming, the more I begin to question the wisdom of OOP concepts like inheritance and polymorphism. I first learned ...
13
votes
1answer
801 views

Why doesn't Haskell have type-level lambda abstractions?

Are there some theoretical reasons for that (like that the type checking or type inference would become undecidable), or practical reasons (too difficult to implement properly)? Currently, we can ...
11
votes
7answers
1k views

Which statically typed languages support intersection types for function return values?

Initial note: This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which ...
11
votes
2answers
436 views

Are types erased in Haskell?

Haskell has a notion of “generic functions” that has some apparent similarity with common lisp—having neither experience with Haskell nor with common lisp, I might be very approximative here. This ...
11
votes
1answer
728 views

(Dis-)advantages of structural typing

I’ve just watched this talk by Daniel Spiewak where he talks about the advantages of structural typing as compared to Scala’s ans Java’s nominal typing. One example for this difference would be the ...
10
votes
3answers
752 views

How do existential types differ from interfaces?

Given the existential type T = ∃X.{op₁:X, op₂:X→boolean} and this generic Java interface: interface T<X> { X op₁(); boolean op₂(X something); } What are the fundamental differences ...
9
votes
4answers
973 views

Type systems: nominal vs. structural, explicit vs. implicit

I'm a bit confused about the difference between nominal and structural type systems. Can someone please explain how they differ? From what I understand: Nominal: Type compatibility is based on type ...
8
votes
9answers
2k views

Mission critical embedded language [closed]

Maybe the question sounds a bit strange, so I'll explain a the background a little bit. Currently I'm working on a project at y university, which will be a complete on-board software for an ...
8
votes
5answers
614 views

Are there programming languages that allow you to do set arithmetic on types?

Out of curiosity, are there languages that allow you to do set arithmetic on types to create new types? Something like: interface A { void a(); void b(); } interface B { void b(); void ...
8
votes
3answers
2k views

Is there a difference between casting and converting types in imperative programming languages?

The question came up in a discussion at StackOverflow. Is there a clean distinction between the two concepts cast and convert (concerning the type of an object), or are these two words describing ...
8
votes
0answers
180 views

Why does OCaml's (and F#'s) type inference algorithm need tagging functions as recursive? [duplicate]

From Real World OCaml (beta): OCaml distinguishes between non-recursive definitions (using let) and recursive definitions (using let rec) largely for technical reasons: the type-inference ...
7
votes
3answers
1k views

Generics and Type-erasure

Generics in Java are implemented using type erasure. The JLS says that the inspiration was backward compatibility. Where as on the other hand C# generics are reifiable. Theoretically what are the ...
7
votes
2answers
444 views

Values, types, kinds, and…?

We all know what a value is. A type is the type of a value. A kind is (loosely) the type of a type. A type constructs a value; a kind constructs a type. So what is the type of a kind, a thing that ...
7
votes
2answers
202 views

Definition of a type

Conceptually, I used to think of types as sets. However, I think I've seen people wishing to distinguish types A, B even if they represent identical collections of values. So I figured a better ...
7
votes
1answer
118 views

I'm being warned that the Monoid I'm creating is an Orphan Instance. Is there a better way to write this functionality in?

type PromptSegment = IO (Maybe String) instance Monoid a => Monoid (IO a) where mempty = return mempty mappend = liftA2 (<>) This behaves exactly how I want for my purposes. For ...
7
votes
0answers
229 views

Using uniqueness types to implement safe parallelism

I've been interested in uniqueness types as an alternative to monads in pure functional languages for some time; unfortunately, this is kind of an esoteric area of CS research and online resources ...
6
votes
3answers
370 views

Is changing the type of a variable partway through a procedure in a dynamically typed language bad style?

In Python (and occasionally PHP) where variables do not have fixed types, I'll frequently perform 'type transformations' on a variable part-way through my code's logic. I'm not (necessarily) talking ...
6
votes
3answers
335 views

What are some reasonable stylistic limits on type inference?

C++0x adds pretty darn comprehensive type inference support. I'm sorely tempted to use it everywhere possible to avoid undue repetition, but I'm wondering if removing explicit type information all ...
6
votes
2answers
2k views

Duck checker in Python: does one exist?

Python uses duck-typing, rather than static type checking. But many of the same concerns ultimately apply: does an object have the desired methods and attributes? Do those attributes have valid, ...
5
votes
1answer
637 views

Maths needed to understand theory behind Haskell's type system?

Recently, I've become deeply interested in Haskell. While attempting to learn new concepts (e.g. the forall keyword and ST monad) and Haskell's type system in general, I continually run into ...
5
votes
1answer
391 views

Why do generics in Scala have erased types, and are not reifiable?

Why do generics in Scala have erased types, and are not reifiable? Is it due to lack of support from the JVM or for compatibility with Java libraries? What are the advantages in general of having ...
5
votes
1answer
492 views

Is there an imperative language with a Haskell-like type system? [closed]

I've tried to learn Haskell a few times over the last few years, and, maybe because I know mainly scripting languages, the functional-ness of it has always bothered me (monads seem like a huge mess ...
4
votes
2answers
223 views

Alternative to language purity

Purity One of the interesting concepts in Haskell is the purity. However, I am wondering what the pragmatic reasons behind this is - let me explain a bit more before you reject my question. My main ...
4
votes
4answers
210 views

objects, classes, types

How does an object oriented programmer understand the word "type"? I'm not aware of there being a type theory for object oriented programming because whenever someone mentions type theory it is always ...
4
votes
2answers
101 views

Correct terminology in type theory: types, type constructors, kinds/sorts and values

In an answer to a previous question, a small debate started about correct terminology for certain constructs. As I did not find a question (other than this or that, which is not quite the right thing) ...
4
votes
2answers
307 views

Nulls in every type and checked exceptions in Java?

I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that ...
4
votes
1answer
252 views

What is the evidence that an API has exceeded its orthogonality in the context of types?

Wikipedia defines software orthogonality as: orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways ...
3
votes
2answers
468 views

How does a dependently typed programming language cope with mutability?

I have been investigating on the viability of a "normal" programming language with dependent types. Think for example in Java and add dependent types to it. One difficulty which I have found is that ...
3
votes
1answer
125 views

A question about static types

How would you statically type the following JavaScript program function c(str) { c = eval(str); return c(str); } I'm not trying to start a flame war but I'm genuinely curious. I've always ...
3
votes
1answer
263 views

When writing an interpreter, how should the type inference algorithm change the parsed AST? Should it?

When writing an interpreter, how should the type inference algorithm chance the parsed AST? Should it? Or parsing and inference are done necessarily simultaneously? I have implemented a strongly ...
3
votes
1answer
557 views

C# type system and dynamic type

I'm writing a paper about the C# (and Go) type system with focus on the dynamic aspect. Does anybody have suggestions for papers/literature? The things I found don't go much into detail. I would ...