* Specialization of generics
@ 2001-06-04 0:17 John Pitney
2001-06-04 1:04 ` tmoran
2001-06-04 10:23 ` Ehud Lamm
0 siblings, 2 replies; 7+ messages in thread
From: John Pitney @ 2001-06-04 0:17 UTC (permalink / raw)
Hello from an Ada newcomer! I'm an experimental physicist with a C/C++
background learning Ada (using GNAT on GNU/Linux on Intel) for use in
numerics and possibly instrument control.
Now the question: Is it possible to define a generic package taking
one or more types as generic formal parameters, and then define that
the generic is instantiated in a different way if the generic formal
parameters match some condition? One application I could think of
would be for an image package to handle 1-bit images in a compact way.
The comp.lang.ada group seems great so far---I've enjoyed lurking for
the last few months!
John
--
John Pitney
johnp789 <at> yahoo.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Specialization of generics
2001-06-04 0:17 Specialization of generics John Pitney
@ 2001-06-04 1:04 ` tmoran
2001-06-04 10:23 ` Ehud Lamm
1 sibling, 0 replies; 7+ messages in thread
From: tmoran @ 2001-06-04 1:04 UTC (permalink / raw)
>the generic is instantiated in a different way if the generic formal
>parameters match some condition?
For example?
You could of course include a boolean constant as a parameter and
then have an "if" select which of two code sequences to run.
>One application I could think of
>would be for an image package to handle 1-bit images in a compact way.
You might want to use tagged types. For instance, in Claw.Bitmaps there's:
type Basic_DIBitmap_Type is abstract new Root_DIBitmap_Type with ...
then various actual types of bitmaps are, eg,
type Mono_DIBitmap_Type (Height, Byte_Width : Claw.Int) is
new Basic_DIBitmap_Type (Height, Byte_Width) with record ...
type VGA_DIBitmap_Type (Height, Width : Claw.Int) is
new Basic_DIBitmap_Type (Height, Width) with record ...
and then the various routines whose implementation is specific to the
color depth are defined, eg,
function Get_Size (Bitmap: in Mono_DIBitmap_Type) return Claw.Size_Type;
-- Return the size in pixel counts of the bitmap.
function Get_Size (Bitmap: in VGA_DIBitmap_Type) return Claw.Size_Type;
-- Return the size in pixel counts of the bitmap.
etc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Specialization of generics
2001-06-04 0:17 Specialization of generics John Pitney
2001-06-04 1:04 ` tmoran
@ 2001-06-04 10:23 ` Ehud Lamm
2001-06-04 14:51 ` Ted Dennison
1 sibling, 1 reply; 7+ messages in thread
From: Ehud Lamm @ 2001-06-04 10:23 UTC (permalink / raw)
> Now the question: Is it possible to define a generic package taking
> one or more types as generic formal parameters, and then define that
> the generic is instantiated in a different way if the generic formal
> parameters match some condition? One application I could think of
> would be for an image package to handle 1-bit images in a compact way.
>
Short answer is that generic specialization as such doesn't exist in Ada.
I am sure others will give plenty of useful suggestions how to overcome this
problem.
--
Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== Me!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Specialization of generics
2001-06-04 10:23 ` Ehud Lamm
@ 2001-06-04 14:51 ` Ted Dennison
2001-06-04 16:16 ` Ehud Lamm
0 siblings, 1 reply; 7+ messages in thread
From: Ted Dennison @ 2001-06-04 14:51 UTC (permalink / raw)
In article <9ffnvi$qtl$1@news.huji.ac.il>, Ehud Lamm says...
>
>> Now the question: Is it possible to define a generic package taking
>> one or more types as generic formal parameters, and then define that
>> the generic is instantiated in a different way if the generic formal
>> parameters match some condition? One application I could think of
>> would be for an image package to handle 1-bit images in a compact way.
>>
>
>Short answer is that generic specialization as such doesn't exist in Ada.
>I am sure others will give plenty of useful suggestions how to overcome this
>problem.
Right. For me the easiest is to just have two generics (one for each
"specilization"). Common code can be put in a separate (possibly non-generic)
package that both generics can use. For instance, we have a set of packages here
for performing multilinear interpolation for specified points using a matrix of
values. There's a generic which allows you to instantiate for the number of
dimensions you want to use. But for 1 dimension and 2 dimensions the algorithms
are much simpler, so they each have their own (non-generic) package.
---
T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
home email - mailto:dennison@telepath.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Specialization of generics
2001-06-04 14:51 ` Ted Dennison
@ 2001-06-04 16:16 ` Ehud Lamm
2001-06-04 17:28 ` Brian Rogoff
0 siblings, 1 reply; 7+ messages in thread
From: Ehud Lamm @ 2001-06-04 16:16 UTC (permalink / raw)
> Right. For me the easiest is to just have two generics (one for each
> "specilization").
> ---
> T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
Yap, that's what I'd do.
What I really miss is being able to overload generic units. For example,
imagine a package that can work on any non-limited type, but has a more
efficient version ("specialization") is the type is ordered (i.e, has an "<"
operator). The client code "simply" instantiates the unit, getting the
appropriate version automagically.
This is great when the internal structure of a library shouldn't really
concern clients, and thus "we manage complexity."
--
Ehud Lamm mslamm@mscc.huji.ac.il
http://purl.oclc.org/NET/ehudlamm <== Me!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Specialization of generics
2001-06-04 16:16 ` Ehud Lamm
@ 2001-06-04 17:28 ` Brian Rogoff
2001-06-04 19:21 ` Ehud Lamm
0 siblings, 1 reply; 7+ messages in thread
From: Brian Rogoff @ 2001-06-04 17:28 UTC (permalink / raw)
On Mon, 4 Jun 2001, Ehud Lamm wrote:
> > Right. For me the easiest is to just have two generics (one for each
> > "specilization").
> > ---
> > T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html
>
>
> Yap, that's what I'd do.
> What I really miss is being able to overload generic units. For example,
> imagine a package that can work on any non-limited type, but has a more
> efficient version ("specialization") is the type is ordered (i.e, has an "<"
> operator). The client code "simply" instantiates the unit, getting the
> appropriate version automagically.
OK, I tried to sit on my hands, but I can't resist. Along these lines, you
can look at
http://www.acm.org/pubs/citations/proceedings/ada/126551/p338-shen/#indterms
which is not exactly what you're talking about but would provide some
similar capabilities. I'd have really liked something like this in Ada.
Who knows, maybe SPARK will evolve into a new language with parametric
polymorphism.
-- Brian
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-06-04 19:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-04 0:17 Specialization of generics John Pitney
2001-06-04 1:04 ` tmoran
2001-06-04 10:23 ` Ehud Lamm
2001-06-04 14:51 ` Ted Dennison
2001-06-04 16:16 ` Ehud Lamm
2001-06-04 17:28 ` Brian Rogoff
2001-06-04 19:21 ` Ehud Lamm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox