Constness and delegates

Mafi mafi at example.org
Sat Jan 11 16:44:33 UTC 2020


On Friday, 10 January 2020 at 21:25:50 UTC, Timon Gehr wrote:
>...
>
> Conceptually, the type of a closure mapping A to B can be 
> described as an existential type ∃C. C×(A×C→B). All type 
> checking rules basically follow from this, for example:
>
> ∃C. immutable(C)×(A×immutable(C)→B)
> =
> ∃C. const(immutable(C))×(A×const(immutable(C))→B)
>> ∃C'. const(C')×(A×const(C')→B)
>> ∃C''. C''×(A×C''→B)
>
> (Where C' is substituted for immutable(C), and C'' for 
> const(C).)
>
> The implementation using void* is an unsafe approximation made 
> necessary by D's type system not being powerful enough, but any 
> code that respects this typing of delegates can be @trusted.

Thank very much for this explanation in particular! It's great to 
know that delegates can have maxmimum flexibility (especially 
'mutable delegate mutable' being the go-to type) while preserving 
soundness.


More information about the Digitalmars-d mailing list