[Haskell-cafe] Name overloading

Bulat Ziganshin bulat.ziganshin at gmail.com
Wed Jan 13 14:01:33 EST 2010

Hello Cristiano,

Wednesday, January 13, 2010, 9:43:06 PM, you wrote:

> coming up to my mind is that type inference actually forbids a
> type-directed resolution of names as in C++ or Java.

you are right. we either have ad-hoc polymorphism like in C++ where
type of id selected based on type of arguments, like in

int open(char *s)
int open(int i)

or two-way type inference where each id has just one type. otherwise,
having both overloaded ids and two-way inference, we will got
polynomial raise of complexity of type inferencing. ie. imagine some

f = a . b . c . d

where a,b,c,d have multiple possible types

there is backdorr to this mechanism - you can define foo inside of
class. moreover, you can use this to overload struct fields:

class HasFoo a b where
  foo :: a -> b

data X = {fooX :: Int}
data Y = {fooY :: Char}

instance HasFoo X Int  where foo=fooX
instance HasFoo Y Char where foo=fooY

although error messages may be not ideal ;)

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list