From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: Re: Unknown constraints and type composition
Date: Fri, 15 Jun 2018 11:34:53 +0200
Date: 2018-06-15T11:34:53+02:00 [thread overview]
Message-ID: <pg017u$fpp$1@dont-email.me> (raw)
In-Reply-To: <pfvhu2$e4a$1@gioia.aioe.org>
On 15/06/2018 07:13, J-P. Rosen wrote:
> Le 14/06/2018 à 19:53, Jeffrey R. Carter a écrit :
>> On 06/14/2018 05:37 PM, Alejandro R. Mosteo wrote:
>>> I think I have read somewhere that types with unknown constraints are
>>> a good way of ensuring you (or your users) don't end with
>>> uninitialized values:
>>>
>>> types Whatever (<>) is [limited] private;
>>>
>>> function Create return Whatever;
>>
>> It's one way. There are others that might be better. Unknown
>> discriminants are more for generic formal types, to show that the
>> generic accepts indefinite actual types.
>>
>> One way to deal with this is to make the full type a record with
>> reasonable defaults for all the components. This works for all versions
>> of the language.
>>
> Even better, the default can be a raise expression (or a function that
> raises an exception for pre-2012), so no uninitialized object can be
> created. This is a run-time check, but a decent compiler would warn you
> at compile time.
Interesting. So you can have the definite type, but you're forced to
provide a initialization, and are warned about it. Seems one trick to
remember, thanks!
next prev parent reply other threads:[~2018-06-15 9:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-14 15:37 Unknown constraints and type composition Alejandro R. Mosteo
2018-06-14 16:19 ` Dmitry A. Kazakov
2018-06-14 16:58 ` sbelmont700
2018-06-14 17:53 ` Jeffrey R. Carter
2018-06-15 5:13 ` J-P. Rosen
2018-06-15 9:34 ` Alejandro R. Mosteo [this message]
2018-07-08 13:53 ` Jacob Sparre Andersen
2018-06-14 21:28 ` Randy Brukardt
2018-06-15 9:37 ` Alejandro R. Mosteo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox