From: mlucius@... (Mike Lucius) Date: 2002-09-12T14:59:22+09:00 Subject: Re: Multimethods (was Re: Larry Wall's comments on Ruby) I think two concepts are getting confused here. Multimethod dispatch and generic programming. Multimethod dispatch (which is like C++ function overloading, but not quite)is when there are two(or more) receivers. It is exactly like C++ function overloading except the method would presumably have access to the internal state of both(all) instances dispatched upon. i.e. it has the status of "method" for both classes. C++ doesn't support this idea directly, but Alexandrescu uses Template Programming to make a fair approximation (using double-dispatch IIRC). Function overloading does the same thing, but functions are not methods and this limits their usefulness. The executive summary for function overloading: For a particular function name different combinations of argument types are mapped to different implementations. Generic programming is when an algorithm (function) is defined, but types are not specified (completely). Types are bound at compile time (C++ Haskell OCAML) or, in the case of dynamic typing, types are checked by the programmer. Ruby does generic programming naturally because types aren't checked. One problem that crops up here is syntax may be confused with semantics (e.g. the + operator doesn't commute with strings). I've noticed that Mix-ins are used to guarantee the semantics of operators in some cases. The executive summary for generic programming: For a particular function name different combinations of argument types are mapped to the same implementation. In C++ generic functions are implemented by the compiler generating overloaded functions as required. IMO it is very ugly Some functional languages, like Haskell, combine the two ideas by allowing functions to be implemented in serveral different ways, but the types of the arguments are specified by patterns so that many different type "signatures" get mapped to one implementation. Mike Lucius