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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f3437064e1091fec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-14 22:16:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newspeer.monmouth.com!news.monmouth.com!shell.monmouth.com!not-for-mail From: ka@sorry.no.email (Kenneth Almquist) Newsgroups: comp.lang.ada Subject: What evil would happen? Date: 15 Jul 2003 01:16:50 -0400 Organization: A poorly-installed InterNetNews site Message-ID: References: <5ad0dd8a.0307111151.4a08f95a@posting.google.com> NNTP-Posting-Host: shell.monmouth.com Xref: archiver1.google.com comp.lang.ada:40278 Date: 2003-07-15T01:16:50-04:00 List-Id: wojtek@power.com.pl (Wojtek Narczynski) wrote: > I feel like with SML like tagged union datatypes I'd be done long > ago... Is there an AI for this maybe? I'm not sure what the problem is here. In SML you can write things such as: datatype tree = Leaf of int | Tree of { value : int, left : tree, right : tree } | Empty In Ada, you achieve the same effect by writing: type Tree_Tag is (Leaf, General_Tree, Empty); type Tree(Tag : Tree_Tag); type Tree_Ptr is access Tree; type Tree(Tag : Tree_Tag) is record case Tag is when Leaf => Leaf : Integer; when General_Tree => Value : Integer; Left : Tree_Ptr; Right : Tree_Ptr; when Empty => null; end case; end record; The Ada code is slightly more complex than the SML code because in Ada we have to include a type declaration for the tag, and have to declare an access type. (The reason we have to declare an access type in Ada but not in SML is that in SML the fields of a tree cannot be modified after a tree is created, so the semantics of SML don't need to distinguish between a tree and a pointer to a tree.) Kenneth Almquist