www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Additional type information

reply "Volodymyr" <iackhtak gmail.com> writes:
"const" and "ref" actually don't change type but add(remove?) 
some constraints. They are somthing like tags on type. Extended 
tags system can add more constraints! E. g. to manage objects 
allocated using different allocators and prevent minxing memory 
operations based on different allocators:

 allocatedBy(GCAllocator) auto a = new Widget;
auto b = new Widget; // deduce  allocatedBy(GCAlloactor)

 allocatedBy(Mallocator) auto c = // allocate array on OS heap
c ~= [3, 4, 5]; // Error! Allocator don't match. This operator 
use GC
// Or even more:
c ~= [3, 4, 5]; // extend array using Mallocator

These tags may be created by user, cooperate with annotations on 
functions or types (they are annotations), be removed or added 
with "cast", take part in overloading, apply automatic deduction 
for itself. It is compile time type informaion that can be used 
if needed and ommited if not.

So how about the thing?
Mar 16 2015
parent reply "Idan Arye" <GenericNPC gmail.com> writes:
On Monday, 16 March 2015 at 17:21:10 UTC, Volodymyr wrote:
 "const" and "ref" actually don't change type but add(remove?) 
 some constraints. They are somthing like tags on type. Extended 
 tags system can add more constraints! E. g. to manage objects 
 allocated using different allocators and prevent minxing memory 
 operations based on different allocators:

  allocatedBy(GCAllocator) auto a = new Widget;
 auto b = new Widget; // deduce  allocatedBy(GCAlloactor)

  allocatedBy(Mallocator) auto c = // allocate array on OS heap
 c ~= [3, 4, 5]; // Error! Allocator don't match. This operator 
 use GC
 // Or even more:
 c ~= [3, 4, 5]; // extend array using Mallocator

 These tags may be created by user, cooperate with annotations 
 on functions or types (they are annotations), be removed or 
 added with "cast", take part in overloading, apply automatic 
 deduction for itself. It is compile time type informaion that 
 can be used if needed and ommited if not.

 So how about the thing?
But `const` and `ref` do change type - http://dpaste.dzfl.pl/57b4086c5644. There simply is an implicit conversions between them and the unqualified types.
Mar 16 2015
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Monday, 16 March 2015 at 18:11:52 UTC, Idan Arye wrote:
 But `const` and `ref` do change type - 
 http://dpaste.dzfl.pl/57b4086c5644.

 There simply is an implicit conversions between them and the 
 unqualified types.
`const` does, but `ref` doesn't. You can check that by inserting `pragma(msg, typeof(x));` into the functions in your example. But there's nevertheless overloading for `ref`.
Mar 16 2015
parent "Volodymyr" <iackhtak gmail.com> writes:
On Monday, 16 March 2015 at 19:52:07 UTC, Marc Schütz wrote:

 `const` does, but `ref` doesn't. You can check that by 
 inserting `pragma(msg, typeof(x));` into the functions in your 
 example. But there's nevertheless overloading for `ref`.
Yeah... You are right, it is unclear and bad example :) And the tags may change a type because they change some rules for the type.
Mar 17 2015