Tag Info

New answers tagged

9

While Generics have been mainstream in the functional programming community for decades, adding generics to object oriented programming languages offers some unique challenges, specifically the interaction of subtyping and generics. However, even if we focus on object oriented programming languages, and Java in particular, a far better generics system could ...


11

There was quite a bit of research into combining generics with subtyping going on about 20 years ago. The Thor programming language developed by Barbara Liskov's research group at MIT had a notion of "where" clauses that let you specify the requirements of the type you are parameterizing over. (This is similar to what C++ is trying to do with Concepts.) ...


29

The use of subtypes creates a lot of complications when doing generic programming. If you insist on using a language with subtypes, you have to accept there's a certain inherent complexity in generic programming that comes along with it. Some languages do it better than others, but you can only take it so far. Contrast that with Haskell's generics, for ...


2

Duck typing is depending upon objects responding to operations (aka messages or method invocations) in a way that's appropriate to them. "If it quacks like a duck, it's sufficiently duck-like to ask it to do duck things." For example, in Python a dict object has an update method. I can code other kinds of objects that also have an update method: class ...


1

The main difference is that structural typing is enforced during static analysis found in statically typed languages, while duck typing is a runtime phenomenon emerging from the object semantics of dynamically typed languages. As an example, take the following Haxe code (runnable here) using structural typing: class Test { static function main() { ...


8

You have described an effect system. It’s true that there are other effect systems than monads, but in practice monads give you a lot of expressive power that you would need to reinvent in any practical effect system you might devise. For example: I start by tagging my I/O procedures with an io effect. My pure functions can still throw exceptions, but ...


9

I think you've reinvented monads! Let's look at what we have here, we can "dirty" a pure computation implicitly and use it in an impure one, and we can call impure function from another impure one. That sounds a lot like monads, we can dirty a pure value with return, to call another function from an impure function, we can just use >>= apply :: (a ...


0

Common Lisp allows you do define new type using not, and, and or operators (see Type specifiers That Combine).


1

Java supports intersections of interface types in some contexts, though it does not so far as I can tell allow the creation of variables of intersection types. Intersection types may come into play, for example, when using the ? : operator. If the second and third operands to that operator are unrelated interfaces which inherit from overlapping sets of ...


2

Suppose one sees the code: someBigLongGenericType variableName = someBigLongGenericType.someFactoryMethod(); If someBigLongGenericType is assignable from the return type of someFactoryMethod, how likely would someone reading the code be to notice if the types don't match precisely, and how readily could someone who did notice the discrepancy recognize ...


2

I think the answer to this is really simple: it saves reading and writing redundant information. Particularly in object oriented languages where you have a type on both sides of the equal sign. Which also tells you when you should or should not use it -- when the information isn't redundant.


1

ISO Dates Well you don't really need dependent types to model a wellformed month, data Month = January | February | March ... | November | December It becomes slightly more painful with the day and year, since those are rather larger. Indeed, the legal representation of a day of the month ...


17

It's true that code is read far more often than it is written. However, reading also takes time, and two screens of code are harder to navigate and read than one screen of code, so we need to prioritize to pack the best useful-information/reading-effort ratio. This is a general UX principle: Too much information at once overwhelms and actually degrades the ...


35

Let's take a look at Java. Java can't have variables with inferred types. This means I frequently have to spell out the type, even if it is perfectly obvious to a human reader what the type is: int x = 42; // yes I see it's an int, because it's a bloody integer literal! // Why the hell do I have to spell the name twice? ...


4

I think type inference is quite important and should be supported in any modern language. We all develop in IDEs and they could help a lot in case you want to know the inferred type, just few of us hack in vi. Think of verbosity and ceremony code in Java for instance. Map<String,HashMap<String,String>> map = getMap(); But you can say it's ...



Top 50 recent answers are included