[fpc-devel] Packages, Generics

Florian Klaempfl florian at freepascal.org
Mon Sep 13 11:57:34 CEST 2010

Am 13.09.2010 11:44, schrieb Willibald Krenn:
>> This is why FPC has specialize (to emphasis this): only class
>> instances having the same specialized generic type are considered
>> being equal: type TList1 = specialize TList<Longint>; TList2 =
>> specialize TList<Longint>;
>> var l1a,l1b : TList1; l2 : TList2;
>> Only l1a and l1b are assignment compatible. This is like records
>> or classes are handled in pascal: even records with exactly the
>> same fields are not assignment compatible
> So, what you are saying is that FPC - with traditional Pascal syntax
> - only supports generics like this:
> type TList1 = type TList<Longint>;
> Hence, I really don't see any good reason for the new 'specialize'
> keyword as everyone familiar with Pascal/Delphi knows the semantics
> of the above declaration. 

I doubt this :)

> OTOH 'specialize' is an additional
> (unfamiliar) keyword and has semantics totally unknown to the world.
> So why not take what's already in the language?

As I said, to emphasis that a new type is created, generic
specialization is something really new to the language. The meaning of
type ... = type ...; is imo very unclear.

> FPC's generics are, however, very different to all other
> implementations of generics that I know of. And I really(!) hope,
> that FPC does not do the C++ like duck-typing, which could give

FPC works in this regard as C++ which is not nice but much more flexible
being not only some type cast wrapper generator as in C# etc.

> But enough about generics, back to packages: I'll start doing an
> implementation for the non-generic part first. Let's see how this
> goes. Since I need to read into fpc source (and do this in my spare
> time), don't expect any spectacular results soon. In case there are
> more people interested in implementing this, some branch in the repo
> would be needed - if I am the only one, I will do this locally on my
> disk.

Let us know if you've something working and regarding the branch: just
tell me if you need one.

More information about the fpc-devel mailing list