[Haskell-cafe] Re: Overloading functions based on arguments?

David Menendez dave at zednenem.com
Fri Feb 13 15:46:30 EST 2009

On Fri, Feb 13, 2009 at 1:29 PM, John A. De Goes <john at n-brain.net> wrote:
> On Feb 13, 2009, at 11:23 AM, Jonathan Cast wrote:
>> Usually `when no ambiguity can arise', no?  Plenty of mathematical
>> practice rests on imprecision and the expectation that the human reader
>> will understand what you mean.  Haskell has to be understandable by the
>> machine (which is less forgiving, but also more reasonable!) as well.
> Yes, and name overloading is decidable for machines as well, as the feature
> exists in numerous languages, and from time to time, we hear talk of the
> feature for Haskell, as well.

ML uses name overloading for + and *. Type classes were originally
invented as a more principled way of dealing with ad-hoc overloading
like that.

I suspect that you can use type classes for any example of name
overloading, if you're willing to turn on enough extensions in GHC.

If we want an expression's value to be completely determined by its
type, we can just do something like this:

class MapFunction a where
    map :: a

instance MapFunction ((a -> b) -> [a] -> [b]) where ...
instance (Ord a, Ord b) => MapFunction ((a -> b) -> Set a -> Set b) where ...

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list