an observation about united modes
chris hermansen
clhermansen@gmail.com
Thu Jun 26 16:45:05 GMT 2025
Good morning,
On Wed, Jun 25, 2025 at 2:56 PM Jose E. Marchesi <jemarch@gnu.org> wrote:
>
>
> > I don't know if that's clear! But as a simple example, if we had
> >
> > op foo = (int i, j) int: ...
> > op foo = (int i, real j) real: ...
> > op foo = (real i, int j) real: ...
> > op foo = (real i, real j) real: ...
> >
> > vs
> >
> > op foo = (union (int, real) i, j) union (int, real):
> > case i in
> > (int ii): case j in
> > (int ij): ...
> > (real rj): ...
> > etc
> >
> > I guess the return type of union (int, real) could be problematic, so
> maybe
> > that throws cold water on my idea.
>
> Note that Algol 68 doesn't have a "deuniting" coercion. So the result
> of your operator "foo" would need to be discriminated using a conformity
> clause.
>
Maybe this is the "real reason" for wanting operator overloading - united
mode parameters are transparent (ish) to the programmer, who calls the
procedure with an argument of any of the united modes; but united mode
return values require extra coding all the time, which would definitely be
a pain in the neck.
Go back to my example for a minute:
op foo = (union (int, real) i, j) union (int, real): ...
is a pain because of the need for the programmer to deal with the results
with a conformity-clause (as you say, no de-uniting).
So instead, in Algol 68 without de-uniting, we need to decompose this into
two operators
op foo_int = (int i, j) int: ...
and
op foo_real = (real i, j) real: ... (which through widening takes the cases
of one argument real, one int)
but then operator overloading allows us to call both of them "foo".
So in a similar way for procedures that take would take united mode
arguments and return united mode results, we are forced to (currently)
write variants (and name them, because we don't have overloading).
Anyway, your point about using modals - I have used generics in Java since
they emerged on the scene and I really like what they have done for my
code. So when I jump up and down cheering for procedure overloading in
Algol 68 I am probably thinking about it mainly as a means to achieve
something similar to what Java generics provide.
As regarding partial parametrization, I think Lindsey observed that Algol
68 supported closures and proposed a mechanism to achieve currying - which
of course isn't a full solution to partial parametrization, but it is a
useful construct.
--
Chris Hermansen · clhermansen "at" gmail "dot" com
C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20250626/f2e04f28/attachment.htm>
More information about the Algol68
mailing list