-
Notifications
You must be signed in to change notification settings - Fork 21
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
Native Number Support and Improvements #562
Comments
Thanks, I added a link to this to the CoreFX doc here: dotnet/corefxlab#1488 This can be considered approved-in-principle. You can go ahead and add an RFC for this if you like (it would be a while before I get any time to look at this) |
@praeclarum you can define a new literal for a prototype of this using custom numeric types |
It seems the C#/.NET teams will be taking an erase-to-IntPtr-plus-metadata-annotations approach to this, see dotnet/corefxlab#1471 (comment) If so this means there is very little work needed for F# here, just deciding on how export happens If anyone spots a change in plan from this please let me know on this thread. |
can we add a modifier too? like for decimal? so like:
this avoid at least for constants let x = 42.0
let y = 3.14
let point = CGPoint (nfloat x, nfloat y) + CGPoint (0.0n, 1.0n)
let angle = atan2 (float point.Y) (float point.X) |> nfloat |
@dsyme what's the status of this? Can we at least apply what @enricosada suggested? |
@realvictorprm Yes, we could apply this, but I'd need to understand the exact final status of the CLR feature |
cc @KrzysztofCwalina for more information about this:
|
@cartermp Looks like C# have not committed to the feature as yet https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-05-26.md#native-ints |
Yeah, I think they're just all-in on getting nullable reference types working 😄 |
I propose we include support for the CLR's new native numbers and C# binding.
I propose:
max
,sqrt
, etc.)The existing way of approaching this problem in F# is:
Xamarin has introduced their own native types (
nint
,nuint
,nfloat
) in theSystem
namespace which are usable but inelegant from F# since they rely heavily on implicit conversions and some constructors are private/internal.F# has native int but it is incompatible with Xamarin's current work and the CLR's future work.
Pros and Cons
The advantages of making this adjustment to F# are that F# can be used for mobile development.
The disadvantage of making this adjustment to F# is it introduces yet another numeric type, one that can be potentially confused with existing support for
System.IntPtr
.Extra informtion
Estimated cost (XS, S, M, L, XL, XXL): S/M (depends on how good we make it)
If you browse Xamarin F# code for native int use, you will see the current state of the art. I think we can do better!
Here is an example of some code using it that isn't too bad: https://gist.github.com/praeclarum/c9e2d1a0f1089cb4025a
But things get much nastier if we want to support arithmetic with some constants or other variables.
As you can see, F# code ends up being littered with types everywhere. In C#, this would be:
Things basically go bad when you start mixing your model data (real data that is platform independent) with the data that native platforms plan to display (which is usually native sized). Problems compound when you start using native data structures (CGPoint) and try to do math with them.
Affadavit (must be submitted)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: