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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: User defined implicit conversion Date: Wed, 30 Oct 2019 16:26:12 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Wed, 30 Oct 2019 21:26:13 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="29383"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader01.eternal-september.org comp.lang.ada:57393 Date: 2019-10-30T16:26:12-05:00 List-Id: "Alain De Vos" wrote in message news:d9269cae-93e5-428c-9c7c-a7a1f5679806@googlegroups.com... > Casting from one type to another is a real pain. > Does the functionality "User defined implicit conversion" exists? > If not are there strategies, general rules, to limit conversion to a > minimum ? > > We don't want as concatination : > result := to_type_a (from_type_a (X) & from_type_a (Y)) ; > when you could have : > result := X & Y ; The only reason you would have that is if you forgot to define "&" for Type_A. Depending on the definition of Type_A, that's unlikely to happen automatically. Ergo, adding function "&" (Left, Right : Type_A) return Type_A is (to_type_a (from_type_a (X) & from_type_a (Y))); Solves the problem in typical use. Implicit conversion itself is the same is eliminating strong typing. If you really want that, you probably need to use subtypes rather than types. That is, "Type_A" should be a subtype rather than a type. For example, instead of: type Type_A is new String; use: Subtype Type_A is String; And now you never need to use a type conversion between Type_A and String. Randy.