|
Generic functions seem kind of like a natural idea once you try to combine
functional programming ( or treating functions a first class objects ) and OO
stuff.
Namely in OO you sort of organize the ADT into a is-a heirarchy of sorts
for example
<collection>
/ \
< array > <sorted-collection>
but everything in that heirarchy "is a " collection. But each has a slight
semantic difference too. The heirarchy goes from the most general down to
the most specific.
Generic Functions are way of grouping "like" functions with "mostly"
the
same semantics. Only they differ on the parameters they take. And
everything in this heirarchy has the same "name".
<function ( t t t ) >
/ \
<function (integer t t )> <function(character t t)>
/ \
<function \
( integer integer t )> \
< function ( charachter integer t ) >
The heirarchy is organized from least specific arguments to most specific
arguments.Just like a heirarchy of class goes from the most general to the
most specific.
However this heirarchy is reflects the heirarchy of the classes of the "data"
classes.
Generic function help enforce this semantic sameness of the all of these
functions by enforcing that they all take the same number of arguments.
I guess my point is that it is still object based. Only the syntax is slightly
more different than
object message
which gets kind of unwiedy once the message itself has arguments.
object message object object object
What's that? its not send a message to a object. Its send a message and
these objects. The specific message implied should depend upon types of
all the objects sent. So what's so strange about just flipping the order of the
first two.
message object object object object
I can see it coming.... "infix notation is more natural than
prefix notation.." :-)
However as outlined in the first part of this message you can still use the
member function" like style of OO in Dylan also.... the reference manual
doesn't particularly represent in neon lights though. ;-)
|