Re: Types in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg63011] Re: Types in Mathematica
- From: "Steven T. Hatton" <hattons at globalsymmetry.com>
- Date: Sun, 11 Dec 2005 04:56:33 -0500 (EST)
- References: <dn38ed$3l7$1@smc.vnet.net> <dn8fof$bnu$1@smc.vnet.net> <dnedoq$11q$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jon Harrop wrote: > Steven T. Hatton wrote: >> Let's assume Vector3d has a conversion operator that returns a string >> representation. I could simply pass it to an output stream that takes a >> string type, and the Vector3d would be converted to a string and put onto >> the stream. No need to explicitly call a conversion function explicitly. > > Overloading is simply done in a different way in Mathematica, e.g. using > inexhaustive pattern matches. This does not make Mathematica less powerful > than C++. In C++ overloading is based on types. There are different parts of the language that participate in this behavior. For the most part, it depends on function call signature matching. The advantage is that I don't need to know the details of everything that can convert to a whatsit when I write a function that takes a whatsit as an argument. Similarly, I don't need to know about every function that takes a whatsit when I create a type conversion operator for a whosit class. Since Mathematica has no concept of function call signature, that cannot be done. I have to do something that explicitly makes the connection between the function and the argument. Either I place the argument pattern in the downvalues of the function, or I put it in the up-values of the argument. In the former, the function specifically references the argument "type". In the latter, the argument "type" specifically references the function. There is a slight advantage that Mathematica up-values have over C++ operator overloading. In C++ there is no "associated" access specifier (something I have suggested to the C++ design committee) that would simply attach a particular operator to the class upon which it operates without granting it any privileged access. Unfortunately, trying to explain what I mean by this, and also how it would be beneficial proved inhibitive. The few people who did understand the idea (including Stroustrup) didn't find it worth retrofitting to the existing language. In the case of up-values, they are attached to the Symbol to which they apply. But in general, overloading in Mathematica is not as flexible as it is in C++. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/