Is polymorphism possible without inheritance?

The best explanation on the subject that I’ve ever read is an article by Luca Cardelli, a renown type theorist. The article is named On Understanding Types, Data Abstraction, and Polymorphism. Types of Polymorphism Cardelli defines several types of polymorphism in this article: Universal parametric inclusion Ad-hoc overloading coercion The kind of polymorphism related to … Read more

If-less programming (basically without conditionals) [closed]

There are some resources on the Anti-IF Campaign site, such as this article. I believe it’s a matter of degree. Conditionals aren’t always bad, but they can be (and frequently are) abused. Additional thoughts (one day later) Refactoring: Improving the Design of Existing Code is a good reference on this subject (and many others). It … Read more

Parametric polymorphism vs Ad-hoc polymorphism

As per the TAPL, §23.2: Parametric polymorphism (…), allows a single piece of code to be typed “generically,” using variables in place of actual types, and then instantiated with particular types as needed. Parametric definitions are uniform: all of their instances behave the same. (…) Ad-hoc polymorphism, by contrast, allows a polymorphic value to exhibit … Read more

Why does Haskell’s `head` crash on an empty list (or why *doesn’t* it return an empty list)? (Language philosophy)

Is polymorphism lost by allowing empty list handling? If so, how so, and why? Are there particular cases which would make this obvious? The free theorem for head states that f . head = head . $map f Applying this theorem to [] implies that f (head []) = head (map f []) = head … Read more

Vector of objects belonging to a trait

Vec<Animal> is not legal, but the compiler can’t tell you that because the type mismatch somehow hides it. If we remove the calls to push, the compiler gives us the following error: <anon>:22:9: 22:40 error: instantiating a type parameter with an incompatible type `Animal`, which does not fulfill `Sized` [E0144] <anon>:22 let mut v: Vec<Animal> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)