Existential vs. Universally quantified types in Haskell

The terms “universal” and “existential” here come from the similarly-named quantifiers in predicate logic. Universal quantification is normally written as ∀, which you can read as “for all”, and means roughly what it sounds like: in a logical statement resembling “∀x. …” whatever is in place of the “…” is true for all possible “x” … Read more

Practical example of Polymorphism

Check the Wikipedia example: it is very helpful at a high level: class Animal: def __init__(self, name): # Constructor of the class self.name = name def talk(self): # Abstract method, defined by convention only raise NotImplementedError(“Subclass must implement abstract method”) class Cat(Animal): def talk(self): return ‘Meow!’ class Dog(Animal): def talk(self): return ‘Woof! Woof!’ animals = … Read more

Learning C++: polymorphism and slicing

This is a problem called “slicing.” Dog() creates a Dog object. If you were to call Dog().makeSound(), it would print “bark” as you expect it to. The problem is that you are initializing the badDog, which is an object of type Animal, with this Dog. Since the Animal can only contain an Animal and not … Read more

Achieving polymorphism in functional programming

Putting functions inside pure data structures in a prototype-like fashion – this seems like it works but doesn’t it also violate the idea of defining pure functions separately from data? If virtual method dispatch is the way you want to approach the problem, this is a perfectly reasonable approach. As for separating functions from data, … Read more

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