I know how to fix interactions templates now

Stefan Koch uplink.coder at gmail.com
Thu Oct 1 05:23:51 UTC 2020


On Thursday, 1 October 2020 at 03:27:45 UTC, Stefan Koch wrote:
> It just came to me.
> I know how to fix the user-visible problems of templates now.
> How to make them debuggable.
> Sadly this only benefits the programmer and not the compiler, 
> since the compilers problems come from static polymorphism 
> mostly.
>
> But for the usage of templates we can fix the soup of if 
> constraints and trying to find which overload should have been 
> picked.
>
> I must have been blind.
> Shame about there not being a compiler speedup potential in it.
>
> But at least I can now have hope  of being able to debug 
> template based code in the future.
> This time however there won't be sneak previews.
>
> I won't make the same mistake twice.
>
> Cheers,
>
> Stefan

Actually.
I just realized I don't care about implementing this at all.
And the idea isn't all that revolutionary ...
So I might as well flesh it out here.

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.

That means all we need to do, is to group constraints (I believe 
this is what C++ calls concepts? I am not sure about this, 
perhaps Andrei or Atila could clarify)

I can imagine a nice implementation of this, but since it doesn't 
solve the performance problem, I am not interested.

I guess a fully polymorphic version of type functions, which is 
by then an implementation first class types, would fix that.

But again polymorphism is exactly what I want to avoid.

Because once things are polymorphic how do you predict the shape?



More information about the Digitalmars-d mailing list