Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Native Number Support and Improvements #562
I propose we include support for the CLR's new native numbers and C# binding.
The existing way of approaching this problem in F# is:
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
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.
let x = 42.0 let y = 3.14 let point = CGPoint (nfloat x, nfloat y) + CGPoint (nfloat 0.0, nfloat 1.0) let angle = atan2 (float point.Y) (float point.X) |> nfloat
As you can see, F# code ends up being littered with types everywhere. In C#, this would be:
var x = 42; var y = 3.14; var point = new CGPoint (x, y) + new CGPoint (0, 1); var angle = Math.Atan2 (point.Y / point.X);
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:
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?
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
@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