[Haskell-cafe] Re: Proposal: TypeDirectedNameResolution
Heinrich Apfelmus
apfelmus at quantentunnel.de
Fri Jul 31 05:50:28 EDT 2009
Ryan Ingram wrote:
> Heinrich wrote:
>> While I do agree that qualified names are annoying at times, I think
>> that type directed name disambiguation is a Pandora's box.
>
> I see where you are going, but I'm not sure I agree. Let me give an
> example from another language with this kind of resolution: C++. From
> a purely practical point of view, function overloading in C++ does
> what I want almost all the time. And when it doesn't do what I want,
> it's always been immediately obvious, and it's a sign that my design
> is flawed.
>
> But those cases where it does what I want have been incredibly useful.
Sure, overloading is useful. But to avoid headache in a polymorphic
language, I'd prefer a principled approach to it. Hence, I'm convinced
that there should be only one mechanism for overloading in Haskell;
which is type classes at the moment.
It appears that type direction name disambiguation can be implemented
with (automatically generated) type classes? Something like this
class Function_lookup t where
lookup :: t
instance Function_lookup (k -> [(k,a)] -> Maybe a) where
lookup = ...
instance Function_lookup (k -> Map k a -> Maybe a) where
lookup = ...
For each ambiguous function, the compiler creates a type class and
corresponding instances and type inference will sort out the rest (or
throw a type error).
Regards,
apfelmus
--
http://apfelmus.nfshost.com
More information about the Haskell-Cafe
mailing list