MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Types in Mathematica

  • To: mathgroup at
  • Subject: [mg63011] Re: Types in Mathematica
  • From: "Steven T. Hatton" <hattons at>
  • Date: Sun, 11 Dec 2005 04:56:33 -0500 (EST)
  • References: <dn38ed$3l7$> <dn8fof$bnu$> <dnedoq$11q$>
  • Sender: owner-wri-mathgroup at

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:
Math for Comp Sci
Math for the WWW:

  • Prev by Date: Re: Re: Using The Random Function to predict Things
  • Next by Date: Re: Types in Mathematica
  • Previous by thread: Re: Types in Mathematica
  • Next by thread: Re: Types in Mathematica