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!news1.google.com!news.glorb.com!news2.telebyte.nl!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: 28 Sep 2004 20:54:02 +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: 1096397642 dtext02.news.tele.dk 172 83.88.108.52:4636 X-Complaints-To: abuse@post.tele.dk Xref: g2news1.google.com comp.lang.ada:4332 Date: 2004-09-28T20:54:02+02:00 List-Id: Georg Bauhaus writes: > Marius Amado Alves wrote: > : Mark Lorenzen wrote: > :> Some things I miss in Ada that are available in ML: Higher order > :> functions, pattern matching and tuples. > > [GNAT.SPITBOL] > > Maybe the phrase "argument pattern matching" should be substituted > for "pattern matching" outside "functional communities", to avoid > misunderstandings. From a user's perspective, argument pattern > matching has little to to with grammar based pattern matching of > strings. Rather, it is distant relative of 'class and case. Right. I meant argument pattern matching. Consider the following data type and it's two value constructors: type Optional_Integer (Defined : Boolean) is record case Defined is when True => Value : Integer; when False => null; end case; end record; I think it would be quite nice to have the possibility to define the following subprograms: procedure Do_Something (I : Optional_Integer(Defined => False)) is begin null; end Do_Something; procedure Do_Something (I : Optional_Integer(Defined => True, Value)) is begin Do_Something_More(Value); end Do_Something; 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.) > > : In Ada you have, respectively: access-to-subprograms types, > > but functions cannot carry their environments with them, to the same > extent? With higher-order functions I also meant that functions should be first-class citizens in the language. In order to use this effectively we also need currying, and lambda expressions. All in all this is probably too much of a change to Ada. > > Mark, did you mean tuple matching when you said that tuples (records > and arrays interchangeably) are missing in Ada? > > -- Georg Yes, tuple matching using the same ideas as above, but also as parameter types and function return types. Simply a short way of defining an anonymous record type. function F ((A, B) : (Positive * Natural)) return (String * Natural); (S, N) : (String * Integer) := F (C, D); This avoids the tedious definition of record types for simple pairs. I think that the pattern matching idea is probably the most useful one for the average programmer and the least intrusive one (language wise). - Mark Lorenzen