[fpc-devel] Allow record helper inheritance in Delphi mode

Stefan Glienke sglienke at dsharp.org
Fri Sep 1 20:33:51 CEST 2017


As I said for me then it's rather useless for what I see the benefit in 
helpers for generic types.

It's not even close to the benefit I get from extension methods in C# 
(yeah, I know generics work a bit different there).

Having really slim interfaces like IEnumerable<T> or IObservable<T> 
which both have only one method but a ton of extension methods that give 
all the power to those types is great not only for extensibility by 
adding more extension methods but also for implementing your own 
enumerables or observables (only need to implement one method!).

Having to put those methods on the interface in pascal which is not even 
possible because some of those extension methods have more than just the 
one generic parameter from the type they are extending is making this 
kind of code very unwieldy (you have to write it in a reverse way 
wrapping static method calls into each other rather than just chaining 
them together).


Am 01.09.2017 um 18:38 schrieb Sven Barth:
>
> Am 01.09.2017 14:50 schrieb "Stefan Glienke" <sglienke at dsharp.org 
> <mailto:sglienke at dsharp.org>>:
> >
> > > For generics the only way to support them is that you must 
> explicitly specialize a generic helper type. The compiler won't do any 
> type inference for you.
> >
> > IMO this makes them rather useless. Is that a technical limitation 
> or just something you did not want to do?
> > I don't know much about compiler internals for forgive me my naivety.
> >
> > If I have TFoo<T> and a TFooHelper<T> and somewhere declare a 
> TFoo<Integer> and use a method
> > from my helper can't the compiler make sure to compile the 
> TFooHelper<Integer> version for it?
>
> What if I do the initial specialization in a unit that does not know 
> about the helper? It can't just do speculative specialization once 
> both the specialized generic and the generic helper are used in the 
> same unit. And even if the compiler would postpone it till some method 
> of the specialized type is called things would get polluted once 
> multiple helpers lee type are allowed as every one of the generic 
> helpers in scope would need to be specialized for overload resolution.
>
> So in short: no, I don't *want* this, but it's due to technical reasons.
>
> > I guess it's because it does not know anymore that TFoo<Integer> is 
> in fact a closed generic type that was constructed from the open 
> geneneric type TFoo<T>?
>
> The compiler can know rather easily that a type is a specialization, 
> but you need to keep in mind that helpers are also active for parent 
> types. So if you descend from a specialization the helpers of the 
> generic would need to be available as well.
>
> Regards,
> Sven
>



---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170901/2a488a12/attachment.html>


More information about the fpc-devel mailing list