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)

1
vote
3answers
274 views

type infered statically typed languages?

are there any typeless typesafe languages? By typesafe I mean types are checked at compile time. By typeless I mean types are not declared. I know this is easier than it sounds, maybe even impossible ...
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 ...
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 ...
2
votes
2answers
136 views

Is there a difference between duck typing and structural typing? [duplicate]

Duck typing is deciding on the type of an object, based on the operations it supports and the attributes it owns. Structural typing is... the same thing? What exactly is the difference?
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 ...
2
votes
1answer
56 views

Is there a way to define a consistent date in a dependent type language?

I am looking for an example (if exists at all) of a definition of a date in a programming language (Idris, Coq, etc) that features dependent types where such definition is consistent and type safe by ...
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 ...
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) ...
2
votes
3answers
198 views

Is 'design with types first' ultimately the same as 'design with interfaces first'?

In Object Oriented Programming, we're taught to think in terms of Polymorphism (the idea that the implementation is decoupled from the interface - and that it makes sense to think of the interface ...
1
vote
2answers
611 views

The Definition of “Strong Type Systems” [closed]

I saw Martin Odersky's "The Trouble with Types" presenstaion. He divided programing-languages in two dimensions in the "Type Systems Landscape" chart; A "Static/Dynamic" dimension and A "Strong/Weak" ...
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
2answers
261 views

Parameterized Java Types (Generics)

Consider this "legacy" code: public interface IPersistentCollection { IPersistentCollection cons(Object o); } Genericized in Java, it could become something like this: public interface ...
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 ...
2
votes
2answers
360 views

Type inference in Golang/Haskell

I've read that Go doesn't actually have true type inference in the sense that functional languages such as ML or Haskell have, but I haven't been able to find a simple to understand comparison of the ...
2
votes
2answers
190 views

Java: method takes varargs of unrelated types

I have a Java factory method with a varargs array of Objects at the end. The array can contain any combination of Strings and ScaledJpegs. The theory being that an HTML table cell can contain any ...
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 ...
1
vote
2answers
187 views

Is there any practical use for the empty type in Common Lisp?

The Common Lisp spec states that nil is the name of the empty type, but I've never found any situation in Common Lisp where I felt like the empty type was useful/necessary. Is it there just for ...
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
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 ...
2
votes
3answers
311 views

If Scheme is untyped, how can it have numbers and lists?

Scheme is said to be just an extension of the Untyped Lambda Calculus (correct me if I am wrong). If that is the case, how can it have Lists and Numbers? Those, to me, look like 2 base types. So I'd ...
7
votes
0answers
230 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 ...
2
votes
1answer
170 views

Interface hierarchy design for separate domains

There are businesses and people. People could be liked and businesses could be commented on: class Like class Comment class Person implements iLikeTarget class Business implements iCommentTarget ...
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 ...
0
votes
1answer
55 views

Would it make sense to add parameters of an inferred type to inheritance?

I'll write this in PHP (where this thought originated), but this is generic to any object-orientated language. Basically, this is an addition to abstract classes that defines the implementation of its ...
0
votes
1answer
198 views

Can we say that Java or C# have unified inheritance trees?

Can we say that Java or C# are OO languages with a unified inheritance tree/unified type system? By unified inheritance tree/unified type system I mean that every class derives implicitly or ...
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 ...
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 ...
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 ...
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. ...
5
votes
1answer
641 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 ...
2
votes
3answers
311 views

Can compilers check whether certain axioms hold for a user defined type?

Suppose the following type is defined (C++ syntax, can be conceptually applied to any statically typed language.) class T { int val; friend bool operator<(const T& lhs, const T& rhs) ...
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 ...
3
votes
1answer
265 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 ...
0
votes
1answer
145 views

Formal definition of “concepts / type system” for parametric types - Where to start?

I would be interested in formally defining (and consequently demonstrating) a "type system" for, well, a type system. More specifically, I would like to explore the idea of what C++ calls concepts for ...
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, ...
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 ...
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 ...
9
votes
4answers
977 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 ...
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 ...
1
vote
1answer
354 views

What does “polyadic” mean in the context of functional programming and type systems?

And how does it (or does not) correspond to "polymorphic"? Occasionally I see this notion like in: Implement and represent polyadic operations. I checked Wiktionary but it only gives a general ...
13
votes
1answer
804 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 ...
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? ...
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 ...
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...