New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nativeptr<'T> should support comparison #1194
Comments
It seems that C# supports these out of the box, so I think it makes sense to support this. See: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/pointer-related-operators. Though I think that many of the other interfaces may be problematic in F#, at least until we have a way to deal with all these static interfaces. Though I guess we could add a bunch of them in a functional way at least by extending the surface area of the |
Probably this should be split into two parts. |
Allowing |
@jl0pd This is very surprising to me as I'm running code right now which stores pointers in a |
Surprisingly F# erases // return type is HashSet<IntPtr>
let set () : System.Collections.Generic.HashSet<nativeptr<int>> = Unchecked.defaultof<_>
// return type is int*
let ptr () : nativeptr<int> = Unchecked.defaultof<_> |
That looks like a bug to me. Having pointers in a collection seems wrong to me and extremely unstable. If pinned, it's gonna be disastrous, if not pinned even more so. They have no place in heap-allocated objects. If you do need them (let's say store some pointer to an unmanaged object) you can always store it as a native int.
Exactly. |
Implementing the interfaces isn't going to be easy, as afaik, F# Core has to remain compatible with .NET Standard 2.0. And, unless I'm mistaken, these interfaces aren't available there, and there's strong reluctance to move to a multi-versioned F# Core. (I'm just repeating what I recall from a previous discussion a similar proposal I made myself, but things may have changed meanwhile) |
We won't do it, likely, since we are targeting netstandard2.0 |
Fair enough. I was mostly trying to avoid doing the cast and wasn't aware of all this background. I thought it would be a straight-forward addition.
My use case is to support xlAsyncReturn via an unmanaged delegate.
I'm keeping the pointers in a |
Thanks for explaining the use case. I’d probably try to capture it through closures, but that may not be feasible. Sounds like rather scary code to try to manage, but maybe there’s simply no other way. |
This is exactly what I'm doing. The consumer side interface reduces to |
Can you use |
I see, you've listed that workaround. To me this is adequate. |
Closing this out as the workaround is adequate. |
Suggestion is to have
nativeptr<'T>
supportcomparison
. Probably it should also support all other interfaces ofnativeint
The current workaround is to cast
nativeptr<'T>
tonativeint
when storing in e.g. aSet
.Pros and Cons
The advantages of making this adjustment to F# are you aren't required to throw away type information to store pointers in a collection.
The disadvantages of making this adjustment to F# are it's work.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): XS or S?
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: