From: dog.ee.lbl.gov!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!hobbes.ph ysics.uiowa.edu!news.uiowa.edu!news@ucbvax.Berkeley.EDU (Douglas W. Jones,201H MLH,3193350740,3193382879)
Subject: Re: Generic Instantiation as Subprogram Body?
Date: 8 Oct 92 19:54:52 GMT [thread overview]
Message-ID: <1992Oct8.195452.10224@news.uiowa.edu> (raw)
>From article <dnsurber.718567247@node_26400>,
by dnsurber@lescsse.jsc.nasa.gov (Douglas N. Surber):
>
> generic
> type T is range <>;
> package P is
> type U is private;
> function "<" (l,r : U) return boolean;
> private
> type U is new T; -- or whatever
> end P;
>
> package body P is
>
> -- the following doesn't work. declared function name hides the
> -- generic actual.
> function "<" is new ...
>
> end P;
I've been bothered by this too. The only solution I've found that works
is to write some long-winded boilerplate in the package body; specifically,
You have to write it like this:
package body P is
function "<" (l,r : U) is
begin
return T'(l) < T'(r)
end "<";
end P;
That is, you declare a stubby procedure that explicitly coerces its two
parameters of type U to the base type T, then applies the < operation you
want for that base type.
I run into this most often when I use a generic list type in the
a package that exports list operations. I'd like to just export the
generic instantiations of the list operations on a specific type, but
I can't do it directly; instead, I have to package the exported operations
with annoying little functions like the one shown above.
Of course, this function can be "inlined", so it should cost nothing at
run-time, but these things make for pages of unnecessary source code!
Doug Jones
jones@cs.uiowa.edu
next reply other threads:[~1992-10-08 19:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-10-08 19:54 dog.ee.lbl.gov!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!hobbes.ph [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-10-15 8:50 Generic Instantiation as Subprogram Body? darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!uknet!
1992-10-14 17:03 yale.edu!jvnc.net!netnews.upenn.edu!uofs!guinness.cs.uofs.edu!beidler
1992-10-08 18:00 Douglas N. Surber
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox