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)

0
votes
2answers
62 views

Are static methods of a class part of its type?

As far as I understand it, classes –as they are supported in OOP languages such as C++, Java, and Scala – define the type of each object I can instantiate with that class. Not all features of a class ...
12
votes
1answer
163 views

Why is Haskell unable to avoid repeated evaluation without the monomorphism restriction?

I just finished learnyouahaskell the other day, and I was trying to make sense of the Monomorphism Restriction, as described by the Haskell Wiki. I think I understand how the MR can prevent repeated ...
109
votes
10answers
8k views

Should we define types for everything?

Recently I got into a problem with the readability of my code. I had a function that did an operation and returned a string representing the ID of this operation for future reference (a bit like ...
0
votes
1answer
94 views

Haskell types for functions

I don't understand the answer to this question: Q: Can Haskell find a type for the function selfapply defined by: selfapply f = f f A: The function selfapply is not typeable in the simple system of ...
4
votes
2answers
111 views

What do you get when you cross a multi-precision integer with a floating-point number?

I'm working on adding multi-precision integers to the suite of numeric types in my APL interpreter, but I'm not sure what to do about the odd type-combinations that now arise. I now have the following ...
1
vote
1answer
41 views

What's the best way to store class/type info in a plugin system in your software?

There are lots of applications like 3ds Max, Maya, etc that allows you to use plugins, where even the default nodes are created as plugins. This is all good but if the developer changes the ...
34
votes
8answers
6k views

Is there a reason to have a bottom type in a programming language?

A bottom type is a construct primarily appearing in mathematical type theory. It is also called the empty type. It is a type that has no values, but is a subtype of all types. If a function's return ...
11
votes
2answers
314 views

Is higher-rank parametric polymorphism useful?

I'm pretty sure everyone is familiar with generic methods of the form: T DoSomething<T>(T item) This function is also called parametrically polymorphic (PP), specifically rank-1 PP. Let's ...
12
votes
1answer
453 views

Why do you need higher kinds?

Some languages allow for classes and functions with type parameters (such as List<T> where T may be an arbitrary type). For example, you can have a function like: List<S> Function<S, ...
14
votes
3answers
2k views

What is the reason of using an interface versus a generically constrained type

In object-oriented languages that support generic type parameters (also known as class templates, and parametric polymorphism, though of course each name carries different connotations), it is often ...
0
votes
2answers
207 views

how does test-driven development prevent us from type errors?

I heard (from Robert C. Martin) an assertion that since dynamic languages don't have static typechecking, people should write unit tests to prevent us from type errors. I'm not sure if I'm following ...
2
votes
2answers
72 views

Are single method interface and function type definition the same?

In a language where it is possible to define interfaces and typedefs (using Dart here): abstract class Receiver { void receive(int quantity); } typedef void Receive(int quantity); abstract class ...
3
votes
0answers
89 views

Using Haskell type classes to enforce commutativity

I want to define a type class for geometric objects that can be intersected together: class Intersect a b c | a b -> c where intersect :: a -> b -> c -- Language extensions: ...
2
votes
1answer
88 views

Managing types and conversions in a compiler

I am trying to determine how to manage types and conversions between types within a compiler that I am writing. The compiler is being written in C#. There are a number of different kinds of types. ...
9
votes
5answers
2k views

class in OOP language and type

In programming language theory, a type is a set of values. E.g. the type "int" is the set of all integer values. In OOP languages, a class is a type, is it? When a class is defined with more than ...
26
votes
6answers
2k views

What are the caveats of implementing fundamental types (like int) as classes?

When designing and implenting an object-oriented programming language, at some point one must make a choice about implementing fundamental types (like int, float, double or equivalents) as classes or ...
1
vote
3answers
302 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
151 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 ...
25
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
166 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?
5
votes
2answers
404 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 ...
3
votes
1answer
78 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 ...
20
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
139 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
224 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
772 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
494 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
349 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 ...
4
votes
2answers
913 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
271 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
133 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
226 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
668 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
291 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
380 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 ...
18
votes
1answer
578 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 ...
3
votes
1answer
179 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 ...
49
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
61 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
215 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
479 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
218 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
2k 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 ...
42
votes
9answers
4k 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. ...
7
votes
1answer
762 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
326 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
185 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
327 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
164 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 ...