comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Private type definition must be definite : but why ?
Date: Mon, 3 Mar 2008 08:29:16 -0800 (PST)
Date: 2008-03-03T08:29:16-08:00	[thread overview]
Message-ID: <549a45f2-e4f3-4d24-84a0-4f59290c4c18@d4g2000prg.googlegroups.com> (raw)
In-Reply-To: ffa21fa0-1a80-41e2-a19e-fab57f33267e@u72g2000hsf.googlegroups.com

On Mar 1, 4:37 pm, "Hibou57 (Yannick Duchêne)"
<yannick_duch...@yahoo.fr> wrote:
> Oops, sorry.... I was to much speedy to see a trouble here.
>
> I just have to use an unknown discriminant part (beceause it is
> private), thus just have to do
>
> > package Xxx
> >   type Data_Row_Type(<>) is private;
> >   ...
> > private
> >    type Data_Row_Type is new String;
> >   ...
> > end Xxx;
>
> And it works, and every body's happy... me first :D
>
> Well, to be honest, I still do not understand why the user have to
> know there is are unknow discriminants somewhere..... the user does
> not need to know.

The "user" has to know that there are unknown *constraints* (which
could be discriminants, or could, as in this case, be array
constraints), so that the user knows that you can't declare a variable
(or other object) of that type without adding constraints.  This is
illegal:

    X : String;

since you have to put array constraints on it.  And if your program
looks like this:

    package Xxx is
        type Data_Row_Type is private;
    private
        DO NOT LOOK IN HERE
    end Xxx;

    with Xxx;
    package Yyy is
        Z : Xxx.Data_Row_Type;
    end Yyy;

If Data_Row_Type could be a "new String", you wouldn't be able to tell
that Z is illegal without looking in the private part of Xxx, and
you're not allowed to look at that.  That's what Bob referred to as
"breaking privacy".

In this case:

    package Xxx is
        type Data_Row_Type(<>) is private;
    private
        DO NOT LOOK IN HERE
    end Xxx;

    with Xxx;
    package Yyy is
        Z : Xxx.Data_Row_Type;  -- ILLEGAL
    end Yyy;

Now Z is illegal, and the "user" can tell that without having to look
in the private part of Xxx.  That would make it OK for Data_Row_Type
to be declared as a String.

When you declare a private type, you'll need to ask: Does your design
require that users of the package declare objects of that type?  If
the answer is "no", then you should put (<>) on the declaration so
that you can make the private type be anything you want.

P.S. If you really need Data_Row_Type to be a string and you need your
users to be able to declare objects of the type, consider
Ada.Strings.Bounded or Ada.Strings.Unbounded.

                                   -- Adam








  reply	other threads:[~2008-03-03 16:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-02  0:23 Private type definition must be definite : but why ? Hibou57 (Yannick Duchêne)
2008-03-02  0:37 ` Hibou57 (Yannick Duchêne)
2008-03-03 16:29   ` Adam Beneschan [this message]
2008-03-02  0:43 ` Robert A Duff
replies disabled

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