[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Time to rewrite dpkg



On Fri, May 21, 1999 at 12:25:58AM +1000, Anthony Towns wrote:
> But yes, you can write an "id()" function which behaves differently depending
> on what is passed to it.

You misunderstand.  id is the identity function, defined for all types
and returns what it is given.  In C++ terms, then:

template <class T>
T id (T t)
{
  return t;
}

and in Haskell

id x = x

with the optional type signature

id :: a -> a

OO people speak of polymorphism.  FP people call that polymorphism
"ad-hoc polymorphism", while the parametric polymorphism commonly
seen in functional languages is usually regarded as superior in most
application areas.

In parametric polymorphism, functions always behave the same way
independent of what data type it is passed.  Functions operate on as
many types is possible: id, for example, does nothing to its argument
so it can be applied to any type.

In ad-hoc polymorphism, you never know what a function does unless you
know the exact type of the argument.  In parametric polymorphism, you
always know what a function does, regardless of what it is applied to.

-- 
%%% Antti-Juhani Kaijanaho % gaia@iki.fi % http://www.iki.fi/gaia/ %%%

                      Good Times are back again!
                  http://www.iki.fi/gaia/zangelding/


Reply to: