comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: User defined implicit conversion
Date: Wed, 30 Oct 2019 23:17:05 +0100
Date: 2019-10-30T23:17:05+01:00	[thread overview]
Message-ID: <qpd251$1ajp$1@gioia.aioe.org> (raw)
In-Reply-To: qpcv5l$sm7$1@franka.jacob-sparre.dk

On 2019-10-30 22:26, Randy Brukardt wrote:

> Implicit conversion itself is the same is eliminating strong typing.

It depends, but arbitrary conversions certainly do.

> 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.

This is a restriction imposed by Ada 83 in order to be able to generate 
such null-conversions. Actually it is not null, a subtype can add a 
constraint and then the conversion must include constraint check.

A more general case is when a subtype can have an independent 
representation and user-defined conversions:

    subtype UTF8_String is String;
       -- The conversion must recode Latin-1 to UTF-8

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2019-10-30 22:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 19:43 User defined implicit conversion Alain De Vos
2019-10-30 19:58 ` Simon Wright
2019-10-30 20:39 ` Egil H H
2019-10-30 21:26 ` Randy Brukardt
2019-10-30 22:17   ` Dmitry A. Kazakov [this message]
2019-11-06  6:19   ` G. B.
2019-10-31 11:18 ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox