[Haskell-cafe] language proposal: ad-hoc overloading

Ryan Ingram ryani.spam at gmail.com
Sun Aug 31 22:06:55 EDT 2008

On Sun, Aug 31, 2008 at 4:21 PM, Jonathan Cast
<jonathanccast at fastmail.fm> wrote:
> It seems as if you're proposing that
>  doubleSet :: Set.Set Int -> Set.Set Int
>  doubleSet = map (*2)
>  doubleList :: [Int] -> [Int]
>  doubleList :: map (*2)
> work, but that you not be allowed to notice that the definitions are
> identical and substitute
>  double = map (*2)
> for both definitions.

Yes, that's exactly what I am suggesting.  This is especially
important because Set cannot be made an instance of Functor because of
the Ord restriction on the elements, so you can't generalize to fmap
without redefining Functor as RestrictedFunctor or some such, which
adds a ton of additional type-level programming that shouldn't be
required for day-to-day work.

I'm not against being able to use "double = map (*2)" generally, but
the evidence I've seen says that the PL theory isn't there yet to do
so without unacceptable performance penalties.  (That definition
violates the monomorphism restriction anyways).

> Sorry, but I use Haskell specifically because I do *not* want to use C++.

I don't think "a language I dislike also has this feature" is a good
argument against a feature.  C++ also has named fields in records, and
a standard I/O library.  Should Haskell not have those either?

  -- ryan

More information about the Haskell-Cafe mailing list