originally opened at codeplex by marten_range
Inheriting a List<'T> in F# is forbidden:
type MyList() =
inherit List<int>()
// Compiler: error FS0945: Cannot inherit a sealed type
However creative C# developers can do this:
class MyList : FSharpList<int>
{
MyList () : base(1, FSharpList<int>.Empty)
{
}
public IEnumerator<int> GetEnumerator ()
{
yield break;
}
}
IMHO FSharpList should include the sealed flag to prevent misuse.
Adding sealed to FSharpList could, I guess, introduce a regression for developers that are overriding FSharpList but I suspect it's a quite rare regression.
Mårten
Comments
dsyme wrote Aug 6, 2014 at 7:25 AM [x]
I would be happy for the "Sealed" flag to be added to this type.
marten_range wrote Aug 7, 2014 at 12:59 PM [x]
Tried to add the [] attribute. Didn't work so I will need to dig more into how the assembly metadata is generated. Should be a good exercise.
marten_range wrote Aug 7, 2014 at 2:44 PM [x]
I think I found a place where sealed can be injected for union cases. Seems to work for types like:
However FSharpList1 despise looking like a union to me is generated differently so FSharpList1 don't get tagged sealed.
FSharpLìst1 special cases (like TailOrNull and HeadOrDefault) has surprised me before so if anyone has any tips on how to control the code generation for FSharpList1 that would be very interesting to me.
Thanks.
originally opened at codeplex by marten_range
Inheriting a List<'T> in F# is forbidden:
However creative C# developers can do this:
IMHO FSharpList should include the sealed flag to prevent misuse.
Adding sealed to FSharpList could, I guess, introduce a regression for developers that are overriding FSharpList but I suspect it's a quite rare regression.
Mårten