RFC: "DOMAIN" types in Tutorial D
Quote from Dave Voorhis on October 25, 2019, 10:23 amQuote from johnwcowan on October 24, 2019, 11:27 pmQuote from Dave Voorhis on October 24, 2019, 10:42 pmIn 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 pmWhat 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 writeop*
, 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. ObviouslyDROP 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).
Quote from johnwcowan on October 24, 2019, 11:27 pmQuote from Dave Voorhis on October 24, 2019, 10:42 pmIn 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 pmWhat 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 writeop*
, 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. ObviouslyDROP 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).
Quote from Rene Hartmann on November 1, 2019, 2:46 pmOne 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.
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.