The Forum for Discussion about The Third Manifesto and Related Matters

Please or Register to create posts and topics.

RFC: "DOMAIN" types in Tutorial D

Acceptable?
Yes, as is.
Yes, with changes. (See posts for details.)
No. (See posts for reasons.)
Other. (See posts for details.)
PreviousPage 2 of 2
Quote from johnwcowan on October 24, 2019, 11:27 pm
Quote from Dave Voorhis on October 24, 2019, 10:42 pm

In a language with multiple dispatch, a type's interface notionally consists of all operator that have a parameter of that type -- and, yes, it grows as operators referencing the type are created -- but it is admittedly a poor choice of terminology and not particularly helpful.

In multiple-dispatch languages, generic functions are not in any sense part of types.

They aren't bundled with or part of types, but the interface to (a value of) a given type is precisely the operators (i.e., procedures and functions) that parametrically reference it.

Quote from johnwcowan on October 24, 2019, 11:27 pm

What does need fixing is static type overloading of existing operators.  It should be possible for users to write operators that allow multiplying a length by a width, or a length by an int or float, and still use the * sign.  Syntactically, you could write op*, as Algol 68 does, or __mul__ as Python does, or just allow a symbolic operator to appear in the place of a <user op name>.

In addition, DROP OPERATOR should allow an optional signature so as to only drop a single overload.  Obviously DROP OPERATOR * is undesirable.

It probably doesn't matter much for a pedagogical language that lives only on paper (or .PDF), but in Rel, I implemented both of these.

An expression like '3 * 4' is actually invoking built-in operator OP_TIMES(INTEGER, INTEGER) RETURNS INTEGER. If you want to multiply an INT by a RATIONAL without CAST_AS_<whatever>, you can define OP_TIMES(INTEGER, RATIONAL) RETURNS RATIONAL. The various operator symbols are internally mapped to equivalent operator names. E.g., + is OP_PLUS(...), - is OP_MINUS(...), etc.

In Rel, DROP OPERATOR MyOperator is invalid. It requires an operator signature. E.g., DROP OPERATOR MyOperator(INT, INT) is valid, assuming there is a MyOperator(INT, INT).

I'm the forum administrator and lead developer of Rel. Email me at dave@armchair.mb.ca with the Subject 'TTM Forum'. Download Rel from https://reldb.org

One option would be to use the syntax from Ada:

TYPE MyType IS NEW INT;

But I am not sure if this is a good idea or not.

PreviousPage 2 of 2