From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!news-mue1.dfn.de!news-fra1.dfn.de!news.tele.dk!not-for-mail Sender: malo@0x5358ce92.boanxx18.adsl-dhcp.tele.dk Newsgroups: comp.lang.ada Subject: Re: Formal and informal type systems? References: <49dc98cf.0408110556.18ae7df@posting.google.com> <413e2fbd$0$30586$626a14ce@news.free.fr> <1vaudzrlvn4pk$.1f0rj8oz9xjb6$.dlg@40tude.net> From: Mark Lorenzen Date: 29 Sep 2004 19:53:30 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: TDC Totalloesninger NNTP-Posting-Host: 83.88.206.146 X-Trace: 1096480410 dtext02.news.tele.dk 157 83.88.206.146:35579 X-Complaints-To: abuse@post.tele.dk Xref: g2news1.google.com comp.lang.ada:4398 Date: 2004-09-29T19:53:30+02:00 List-Id: "Dmitry A. Kazakov" writes: > But this is already possible. Consider the following: > > type Optional_Integer (Defined : Boolean) is tagged record > case Defined is > when True => Value : Integer; > when False => null; > end case; > end record; > > type Defined_Integer is > new Optional_Integer (True) with null record; > > type Undefined_Integer is > new Optional_Integer (False) with null record; > > procedure Do_Something (I : Defined_Integer) is > begin > Put_Line ("Defined:" & Integer'Image (I.Value)); > end; > > procedure Do_Something (I : Undefined_Integer) is > begin > Put_Line ("Undefined"); > end; > > The point is that there is no need to invent extra parameter matching > mechanism. One should use and possibly extend the existing one based on > inheritance. In your example, the correct function is chosen by dispatching (or?). This would work, but it does not bind any variables in the argument pattern. It can of couse always be done in Ada, I just think that pattern matching is a very elegant technique, that is often unknown to programmers. > > > The pattern matching could also be extended to case statements such as: > > > > procedure Do_Something (I : Optional_Integer) is > > begin > > case I is > > when Optional_Integer'(Defined => False) => null; > > when Optional_Integer'(Defined => True, Value) => > > Do_Something_More(Value); > > end case; > > end Do_Something; > > > > (Credit goes to one of my colleagues for the idea of using the type > > name as constructor in the patterns.) > > I don't understand this example. Looks just like a class-wide of > Optional_Integer. Am I right? The proposal does not have anything to do with tagged types, but discriminated records where Defined is the discriminant. > To start with, we could introduce function types. I cannot understand why > we have access-to-function types and still have to types for the target. Function types would be very cool, but it is probably be a huge change in the language. We would end up with a language based more or less directly on the lambda calculus and the applicative languages are much better at that. > That requires structured type matching, which is a bad idea, in general. Generally yes. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de Regards, - Mark Lorenzen