I know how to fix interactions templates now
FeepingCreature
feepingcreature at gmail.com
Thu Oct 1 07:39:04 UTC 2020
On Thursday, 1 October 2020 at 05:23:51 UTC, Stefan Koch wrote:
> The reason why templates are so bad at being composable, is
> because template constraints don't compose.
>
> when a template T with constraints(C) yields an valid instance,
> that proofs the constraints hold.
> which implies that for anything using an instance of T the
> constraints C also hold.
>
> When we compose functions our constraints are coupled to types.
> Because templates themselves are (or can be) untyped in both
> Parameters and "return value".
> We can't use those to carry the constraints forward.
>
> Leading us into a case where we have to repeat the same
> constraints over and over again.
>
Yep.
Right now, constraints are carried forward invisibly through
gagged template instantiation via __traits(compiles).
Miscompilation *itself* becomes the propagated constraint
failure, which is of course horrible.
This is why I want __traits(canInstantiate), so we can at least
*enforce* that constraints are manually carried forward by the
programmer. If a template passes its constraints, it should also
pass semantic2/3 in full. It should never be necessary to gag
errors after the constraints.
Body SFINAE is cancer.
More information about the Digitalmars-d
mailing list