Skip to content
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

Add `uint` type abbreviation to FSharp.Core #818

Open
cartermp opened this issue Dec 9, 2019 · 4 comments
Open

Add `uint` type abbreviation to FSharp.Core #818

cartermp opened this issue Dec 9, 2019 · 4 comments

Comments

@cartermp
Copy link
Member

@cartermp cartermp commented Dec 9, 2019

Title of Suggestion

I propose we add the following type abbreviation:

type uint = uint32

The existing way of approaching this problem in F# is to:

  • Write the abbreviation yourself
  • Use uint32 directly

Pros and Cons

The advantages of making this adjustment to F# are:

  • Consistency with int, which is similarly abbreviated to int32
  • Probably helps with the principal of least surprise - if int exists, why not uint?

The disadvantages of making this adjustment to F# are that it's work.

Extra information

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

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • 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:

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

This comment has been minimized.

Copy link

@abelbraaksma abelbraaksma commented Dec 9, 2019

Considering that C# also has uint I think this serves the principle of least surprise.

Note that the F# cheatsheet already assumed that uint exists: https://github.com/tomi/fsharp-cheatsheet, apparently it comes natural to think it does.

Apart from the type abbreviation, for parity, I suggest we also allow the type-cast function val uint32 : value:'T -> uint32 (requires member op_Explicit) to be aliased as val uint : value:'T -> uint (requires member op_Explicit).

Btw, while we're at it, we have aliases for double vs float, but not for int64 vs long and uint64 vs ulong, however the type suffixes suggest long and ulong (L vs UL), which is odd and confusing. Perhaps we could pair them in the same go? For people coming from C# this would certainly help.

And it's just simpler typing without those digits ;).

@abelbraaksma

This comment has been minimized.

Copy link

@abelbraaksma abelbraaksma commented Dec 9, 2019

Funny, even the F# error messages assume uint exists (and doesn't know of uint32 here)!

image

And another aside, apparently this idea is not new (incl. long and ulong), but "Bug 1029" does not seem to refer to a public bug on Github, so its resolution and reasoning is hidden: https://github.com/dotnet/fsharp/blob/0aacd6314172f441a5023396e21ca7baf493494a/tests/fsharp/core/libtest/test.fsx#L4752-L4760

And this is probably a bug, currently (but would magically be solved after this is in): https://github.com/dotnet/fsharp/blob/359b9c1c5eced4ebda24705d29ea99d098d27b87/src/utils/sformat.fs#L147

All the more reason to support this 💯

@cartermp

This comment has been minimized.

Copy link
Member Author

@cartermp cartermp commented Dec 9, 2019

@abelbraaksma Yes, there are some pre-existing assumptions in the codebase that it exists. Looking at the github history, the lack of uint type abbreviation starts when the code was imported to GitHub, so if there is a bug, it is from a bygone era 😄

@Swoorup

This comment has been minimized.

Copy link

@Swoorup Swoorup commented Jan 17, 2020

For some reason I read the whole RFC as uintunit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.