From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Overring function and its returned type
Date: Fri, 09 Nov 2012 22:10:05 +0100
Date: 2012-11-09T22:10:05+01:00 [thread overview]
Message-ID: <op.wniye3txule2fv@cardamome> (raw)
In-Reply-To: 97a6946f-a707-4dd3-872b-9e851fcf9462@googlegroups.com
Le Fri, 09 Nov 2012 20:57:21 +0100, <sbelmont700@gmail.com> a écrit:
> More generally, you are talking about 'covariant return types', which is
> a feature only a handful of languages support (notably C++).
May be (I feel to remember this, while unsure).
> IMHO, i don't really see the need for it; a type is either a child (and
> matches the parent, as in P3) or it doesn't and it's not (as in P2).
> The whole point is to use the abstract parent classwide type
> exclusively, so I never saw the need to tinker around with the concrete
> child types (i would be interested in a real life scenario in which you
> would want this construct)
I won't post here the real thing, I'm only OK to post samples and
snippets. You will have to trust me when I say it make sense (so much, I
wrote things straight away, without suspecting it could be rejected).
Still, to give you an idea, imagine this:
In `P3` spec, replace the definition of `F` with this one:
overriding
function F
(E : T)
return P1.R'Class
with Post'Class =>
F'Result in R'Class;
Then, a sample use case would look like this:
A : P3.T;
B : P3.R'Class := P3.R'Class (A.F);
That looks weird, as much weird as writing something like this:
type IST is new Integer range 1 .. 10;
function F return Integer
with Post =>
F'Result in 1 .. 10;
function F return Integer
is begin
return 1;
end;
D : IST := IST (F);
Reading the above, one may say “that's silly, if you know the returned
type, just specify it in the declaration, and this would additionally
avoid a cumbersome checked conversion at every call place”. That's exactly
what I feel adding a postcondition to `F` just to state what the returned
type is, and adding a conversion at the call place. My words may looks a
too hard, but I would say I would expect Ada to not require to specify
types via pre/post condition, but in signature instead.
I will also try to workaround with an overloading instead of an
overriding, but I'm afraid of getting into a mess with this solution. Will
choose which cause the less troubles, and although the
postcondition+conversion solution looks like bloat, I believe that's still
the safest. I will still try both to really get an idea…
--
“Syntactic sugar causes cancer of the semi-colons.” [1]
“Structured Programming supports the law of the excluded muddle.” [1]
[1]: Epigrams on Programming — Alan J. — P. Yale University
next prev parent reply other threads:[~2012-11-16 9:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-09 7:13 Overring function and its returned type Yannick Duchêne (Hibou57)
2012-11-09 7:22 ` Yannick Duchêne (Hibou57)
2012-11-09 8:24 ` Dmitry A. Kazakov
2012-11-09 9:14 ` Yannick Duchêne (Hibou57)
2012-11-09 13:11 ` Dmitry A. Kazakov
2012-11-09 21:36 ` Yannick Duchêne (Hibou57)
2012-11-09 19:24 ` Adam Beneschan
2012-11-09 19:34 ` Adam Beneschan
2012-11-09 22:00 ` J-P. Rosen
2012-11-09 22:30 ` Yannick Duchêne (Hibou57)
2012-11-09 19:57 ` sbelmont700
2012-11-09 21:10 ` Yannick Duchêne (Hibou57) [this message]
2012-11-09 21:56 ` sbelmont700
2012-11-10 0:28 ` Yannick Duchêne (Hibou57)
2012-11-10 2:35 ` Yannick Duchêne (Hibou57)
2012-11-15 15:13 ` Peter C. Chapin
2012-11-16 10:40 ` Maciej Sobczak
2012-11-16 12:39 ` Peter C. Chapin
2012-11-16 15:27 ` Maciej Sobczak
2012-11-16 17:29 ` Peter C. Chapin
2012-11-17 4:16 ` Yannick Duchêne (Hibou57)
2012-11-17 19:11 ` Robert A Duff
2012-11-18 14:53 ` AdaMagica
2012-11-19 8:41 ` Yannick Duchêne (Hibou57)
2012-11-19 13:04 ` AdaMagica
2012-11-19 15:19 ` Dmitry A. Kazakov
2012-11-19 23:42 ` Randy Brukardt
2012-11-10 7:55 ` Randy Brukardt
2012-11-11 1:02 ` Yannick Duchêne (Hibou57)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox