Quoting Richard O'Keefe <o...@cs.otago.ac.nz>:


On 3/10/2011, at 7:15 AM, 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?

It's not "SIMPLE overloading" you are asking for,
but "AD HOC overloading", which may look simple, but really isn't.

Taking your C++ f() example, in what sense are the two functions _the same function_?




I understand that functions with the same name but different type signatures are not the same function, but are a family of functions,probably representing the same concept.

Also

identityInHaskell::a->a
identityInHaskell x = x
--I don't know if this is implemented as runtime polymorphism or compile-time polymorphism,
--but it is possible to implement this as compile-time polymorphism.

and

template< typename T > T IdentityInCPP( T x ){ return x; }

are families of different functions.

I think the problem I have encountered can be broken down to 2 problems:

1. Haskell doesn't have a way to represent mapping from one type to another (consider metafunctions in C++), which is addressed by TypeFamilies.

2. Haskell disallows ad-hoc overloading. But I think implementing ad-hoc overloading itself should be no more complex than implementing type classes, perhaps it would tear a hole somewhere else?



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to