[Haskell-cafe] Is it possible to represent such polymorphism?

Scott Turner 2haskell at pkturner.org
Sun Oct 2 22:38:21 CEST 2011

On 2011-10-02 14:15, Du Xi wrote:
> I guess this is what I want, thank you all. Although I still wonder why
> something so simple in C++ is actually more verbose and requires less
> known features in Haskell...What was the design intent to disallow
> simple overloading?

"Simple overloading" is known as ad-hoc polymorphism, while Haskell's
type system is based on parametric polymorphism.  As Wikipedia says,
"Parametric polymorphism is a way to make a language more expressive,
while still maintaining full static type-safety."

For example, functional programming gets a lot of power out of passing
functions as arguments. Compare what this gives you in C++ versus
Haskell.  In C++ an overloaded function has multiple types, and when a
function appears as an argument one of those types is selected.  In
Haskell, a polymorphic function can be passed as an argument, and it
still can be used polymorphically within the function that receives it.

When each name in the program has just one type, as in Haskell, type
inference can be much more effective. Type declarations are not
required. Most of the type declarations in my own Haskell code are there
either for documentation, or to ensure that the compiler will catch type
errors within a function definition.

More information about the Haskell-Cafe mailing list