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

sdiyazg at sjtu.edu.cn sdiyazg at sjtu.edu.cn
Mon Oct 3 08:31:52 CEST 2011

Quoting Richard O'Keefe <ok at 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.


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.


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  

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?

More information about the Haskell-Cafe mailing list