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

Re: Multimethods 101 (was Re: Multiple dispatch (Re: Q: Python 2.0 preliminary features?))



Robin Becker wrote:
> 
> In article <381A421D.D8C8E22F@bigfoot.com>, Louis Madon
> <madonl@bigfoot.com> writes
> >
> ...
> I'm a bit confused here after seeing the argument presented as a
> function of only two types. Say I implement + for floats and then Tim
> does it for rationals then in terms of functional mappings + has 2
> inputs and one output ie 3 possible types are involved.
> 
> Thus my take is that we have
> 
> f  f  and r  r
>  f +       r +
> 
> after the combination we have
> 
> f  f r and r f r
>   f+ .      f. .
>   r. .      r. +
> 
> so to my way of thinking to fill in we seem to have to modify the
> existing operators or provide the mapping f-->r or r-->f
> --
> Robin Becker

Well a rational need not require two inputs if you present it as an
object but I understand what you're getting at.  In dylan at least,
there is the notion of "method congruence".  All methods added to a
multimethod must have the same signature (ie. interface) - only the
argument types can differ (well its a bit more sophisticated than that
but thats the basic idea).  That guarantees that clients can always do
the add (or whatwever) in a generic way without concern for the make up
of the individual types.  Ofcourse you can always define additional
multi-methods to express a general concept in a different style.

Louis.



References: