comp.lang.ada
 help / color / mirror / Atom feed
From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov)
Subject: Re: Parametrically polymorphic operations (Was: Safe C++)
Date: Thu, 20 Sep 2001 16:22:17 GMT
Date: 2001-09-20T16:22:17+00:00	[thread overview]
Message-ID: <3baa13ac.4589834@news.cis.dfn.de> (raw)
In-Reply-To: 3BA9D515.1E6C7A49@nbi.dk

On Thu, 20 Sep 2001 13:37:57 +0200, Jacob Sparre Andersen
<sparre@nbi.dk> wrote:

>Chad:
>
>> "Brian Rogoff" <bpr@shell5.ba.best.com> wrote in message
>[...]
>> > Parametrically polymorphic functions
>
>> I'll have to trust you or these three since I have never encountered a
>> situation where I was ever wishing for such functionality.
>
>While working on libraries for matrix operations and unit
>safe types, I have certainly wanted something very similar
>to parametrically polymorphic functions. It would make it
>possible to have more extensive compile time checks, than
>what is possible with Ada as it is defined today.
>
>An example:
>
>   type Matrix (Left, Right : Positive) is private;
>
>   function "*" (Left  : in Matrix;
>                 Right : in Matrix (Height => Left.Width))
>     return Matrix (Width  => Right.Width,
>                    Height => Left.Height);
>
>(I hope the intention is clear although the syntax isn't
>defined)
>
>This would tell the compiler a few things, which would allow
>it to
>flag type mismatches already at compile time.
>
>The current Ada specification forces us to move these checks
>into the body of the functions and procedures.

It is more than that. Same problem appears with implementation of
measurement units [and many other cases].

The actual problem is that a type has some parameters [better to call
them discriminants] that are statically known. These parameters are
involved in some expressions with are also static. One should somehow
separate these expressions from the implementation of the subroutine
body and force them evaluated at compile time. The question is how?
(:-))

Then I would argue that it is not parametric polymorphism, because
there is no need to provide parameters for the body. There is also no
need to have distinct types for matrices of different size [or for
each measurement unit etc]. One need to only "distill" the static part
from the body.

Regards,
Dmitry Kazakov



  parent reply	other threads:[~2001-09-20 16:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-18 19:45 Safe C++ Richard Riehle
2001-09-19 14:38 ` Brian Rogoff
2001-09-19 15:52   ` Chad Robert Meiners
2001-09-19 17:43     ` Brian Rogoff
2001-09-19 21:38       ` Chad R. Meiners
2001-09-20  3:38         ` Brian Rogoff
2001-09-20 11:52           ` Pat Rogers
2001-09-20 16:01             ` Brian Rogoff
2001-09-20  8:22         ` Colin Paul Gloster
2001-09-20 13:45           ` Chad R. Meiners
2001-09-20 21:03             ` codesavvy
2001-09-20 11:37         ` Parametrically polymorphic operations (Was: Safe C++) Jacob Sparre Andersen
2001-09-20 11:41           ` Lutz Donnerhacke
2001-09-20 12:27             ` Jacob Sparre Andersen
2001-09-20 15:49           ` Brian Rogoff
2001-09-21  9:24             ` Jacob Sparre Andersen
2001-09-20 16:22           ` Dmitry A. Kazakov [this message]
2001-09-21 16:08           ` Wes Groleau
2001-09-21 17:13             ` Jacob Sparre Andersen
2001-09-21 18:43               ` Wes Groleau
2001-09-20  2:41       ` Safe C++ David Botton
2001-09-20  2:39   ` David Botton
2001-09-20  3:21     ` Brian Rogoff
2001-09-20 12:43       ` David Botton
2001-09-25 14:21   ` Region-based mem mgmt [was: Re: Safe C++] Tucker Taft
2001-09-25 14:46     ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox