fslang-suggestions icon indicating copy to clipboard operation
fslang-suggestions copied to clipboard

voidptr should be considered as an unmanaged type

Open Happypig375 opened this issue 3 years ago • 2 comments

https://github.com/dotnet/fsharp/issues/11424 Currently F# does not treat voidptr as an unmanaged type. Therefore types like nativeptr<voidptr>, etc. cause compiler errors.

However on IL level this works and C# libraries (e.g. Silk.NET.OpenGL) expose methods expecting this kind of argument (which currently can't be created in F# due the above) image

The existing way of approaching this problem in F# is to make use of C# to wrap around problematic methods.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Consistency with C#
  2. Convenience
  3. Less surprises

The disadvantages of making this adjustment to F# are that native interop is not an area F# focuses on. However, it's still beneficial to unblock scenarios where we must make use of C#.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): XS to S

Related suggestions: https://github.com/dotnet/fsharp/issues/11424

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • [x] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • [x] I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • [x] This is not a breaking change to the F# language design
  • [x] I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Happypig375 avatar Jun 24 '22 06:06 Happypig375

Agree, in practice I currently often just fall back to nativeint to work around type juggling headaches that arise because of this.

reijerh avatar Jun 28 '22 08:06 reijerh

Agreed, this feels like something that's just the right thing to do. I have approved this in principle. While I cannot speak for the priority of the team to implement, I think this would also make a fine contribution to F# vNext.

cartermp avatar Oct 03 '22 07:10 cartermp