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!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Sender: malo@0x53586c34.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> From: Mark Lorenzen Date: 29 Sep 2004 11:11:40 +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.108.52 X-Trace: 1096449101 dtext02.news.tele.dk 170 83.88.108.52:38860 X-Complaints-To: abuse@post.tele.dk Xref: g2news1.google.com comp.lang.ada:4366 Date: 2004-09-29T11:11:40+02:00 List-Id: Stephen Leake writes: > Mark Lorenzen writes: > [some examples removed] > > > > 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; > > I'm sorry, but I have no idea what semantics you intend this new > syntax to represent. I don't know ML, so I can't guess. Please treat > this as a chance to entice me to learn more about ML. > > How, exactly, is your Do_Something different from: > > procedure Do_This (I : Integer) is > begin > case I is > when False => null; > when True => > Do_Something_More(Value); > end case; > end Do_Something; I assume that you meant: procedure Do_This (I : Optional_Integer) is begin case I.Defined is when False => null; when True => Do_Something_More(Value); end case; end Do_Something; It not different, but instead of referring to the discriminant, my example matches the possible ways that I can be constructed. I another answer to your article, Georg Bauhaus showed the definition of a function called 'even' that matched it's argument against 3 possible pattaerns. > > In particular, where is "Value" coming from? It appears to be a global > variable. No it is bound in the match when Optional_Integer'(Defined => True, Value) => ... Here Value is bound to I.Value. Maybe this was a bad name to use in the pattern, so we could also write: when Optional_Integer'(True, V) => ... Which would match a value of type Optional_Integer, where the value of I.Defined is true and V is assigned the value of I.Value. V should probably be delared before it can be used in a pattern. > > You mention "pattern matching", but I have no clue what dataspace you > are matching against. > > -- > -- Stephe