Re: [fpc-pascal] Option type

2021-06-01 Thread Sven Barth via fpc-pascal
Am 02.06.2021 um 03:45 schrieb denisgolovan: You simply can't use managed types in a variant clause and as T could be a managed type the compiler does not allow it. Well. I thought it should be precisely the case for variant clause to properly handle. Compiler knows IsSome field is used to

Re: [fpc-pascal] Option type

2021-06-01 Thread denisgolovan via fpc-pascal
> You simply can't use managed types in a variant clause and as T could be > a managed type the compiler does not allow it. Well. I thought it should be precisely the case for variant clause to properly handle. Compiler knows IsSome field is used to determine if some contains initialized

Re: [fpc-pascal] Option type

2021-06-01 Thread Ryan Joseph via fpc-pascal
> On Jun 1, 2021, at 5:05 PM, Henry Vermaak wrote: > > https://en.wikipedia.org/wiki/Option_type Yeah just use Nullable then since it sounds like that's the closest we're going to get in FPC. Regards, Ryan Joseph ___ fpc-pascal maillist

Re: [fpc-pascal] Option type

2021-06-01 Thread Henry Vermaak via fpc-pascal
On Tue, 1 Jun 2021, 23:39 Ryan Joseph via fpc-pascal, < fpc-pascal@lists.freepascal.org> wrote: > > > > On Jun 1, 2021, at 12:56 PM, denisgolovan > wrote: > > > > That would limit supported types to class instances. > > I'll like to avoid that. > > Ideally TOption type should allow any type

Re: [fpc-pascal] Option type

2021-06-01 Thread Sven Barth via fpc-pascal
Am 01.06.2021 um 20:20 schrieb denisgolovan via fpc-pascal: Hi all I am trying to implement Option type in FPC. type generic TOption = record case IsSome:boolean of true: ( some: T ); false: (); end; However fpc just emits errors: Error: Type parameters may require

Re: [fpc-pascal] Option type

2021-06-01 Thread Виктор Матузенко via fpc-pascal
Why `case`? You can make the same with a plain record: type generic TOption = record IsSome: boolean; some: T; end; вт, 1 июн. 2021 г. в 21:26, denisgolovan via fpc-pascal < fpc-pascal@lists.freepascal.org>: > Hi all > > I am trying to implement Option type in FPC. > > type >

Re: [fpc-pascal] Option type

2021-06-01 Thread denisgolovan via fpc-pascal
> You need to use a constraint like: > > type > generic TOption = record > case IsSome:boolean of > true: ( some: T ); > false: (); > end; > > Not sure why though. > > Regards, > Ryan Joseph That would limit supported types to class instances. I'll like to avoid that. Ideally TOption type

Re: [fpc-pascal] Option type

2021-06-01 Thread Ryan Joseph via fpc-pascal
> On Jun 1, 2021, at 12:56 PM, denisgolovan wrote: > > That would limit supported types to class instances. > I'll like to avoid that. > Ideally TOption type should allow any type (primitives, strings, objects, > class instances, etc). What are you trying to make that requires a variant

Re: [fpc-pascal] Option type

2021-06-01 Thread Ryan Joseph via fpc-pascal
> On Jun 1, 2021, at 12:20 PM, denisgolovan via fpc-pascal > wrote: > > Hi all > > I am trying to implement Option type in FPC. > > type > generic TOption = record >case IsSome:boolean of >true: ( some: T ); >false: (); > end; You need to use a constraint like: type generic

[fpc-pascal] Option type

2021-06-01 Thread denisgolovan via fpc-pascal
Hi all I am trying to implement Option type in FPC. type generic TOption = record case IsSome:boolean of true: ( some: T ); false: (); end; However fpc just emits errors: Error: Type parameters may require initialization/finalization - cannot be used in variant records Could