Hi all, If type inference is not planned, then do you have an alternative to support linq like expression methods ? If type inference is not used then the syntax is very verbose if not ugly.
Also I though that type inference is kind of important for proper lambda support but I might be wrong. Anyways congratulations, very nice feature. Thank you Chriss Kalogeropoulos On Nov 22, 2015 11:32 AM, "Sven Barth" <pascaldra...@googlemail.com> wrote: > On 22.11.2015 00:04, Anthony Walter wrote: > >> Sven, first off, congratulations and we thank you for so much good work. >> in the future do you see a time when type inference could be used? >> >> S := Add('hello ', 'world'); >> I := Add(1, 2); >> > > I honestly don't think that type inference should become part of Pascal, > it's simply not part of the language philosophy and it would also not play > well with the need for "specialize" in ObjFPC mode and as long as Delphi > doesn't introduce it I won't add it only for mode Delphi either. > > Which then brings to mind, will it be possible to get use references to >> generic routines? >> > > If you have read the limitations part of my mail then you should know that > this is a known limitation and to be addressed in the future. > > type >> TTransform<T> = function<T>(const A, B: T): T; >> > > FPC already supports this, though the syntax is > > === code begin === > > type > TTransform<T> = function(const A, B: T): T; > > === code end === > > Or with added "generic" keyword in case of non-Delphi modes. > > var >> Transform: TTransform<T>; >> > > This is not a valid type declaration and never will be, because "T" is not > defined. The correct one is > > === code begin === > > var > Transform: TTransform<String>; > > === code end === > > begin >> Transform := Add<String>; >> WriteLn(Transform('hello', 'world')); >> Transform := Min<String>; >> WriteLn(Transform('hello', 'world')); >> Transform := Max<String>; >> WriteLn(Transform('hello', 'world')); >> end; >> > > This would work once assignments of routines work. In non-Delphi modes the > syntax will be > > === code begin === > > Transform := @specialize Add<String>; > Writeln(Transform('hello', 'world')); > > === code end === > > function Print<T>(const A, B: T; Transform: TTransform<T>); >> begin >> WriteLn(Transform(A, B)); >> end; >> >> begin >> Print('hello', 'world', Add); // type inference >> Print('hello', 'world', Min); >> Print('hello', 'world', Max); >> end; >> > > No type inference. > > Regards, > Sven > > _______________________________________________ > fpc-devel maillist - fpc-devel@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel >
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel