Different semantics between int and bigint

> int "123";;
val it : int = 123
> bigint "123";;
  bigint "123";;
  ^^^^^^^^^^^^
error FS0041: No overloads match for method 'BigInteger'. The available overloads are shown below.
...

Huh? So I tried Parse method instead:

> bigint.Parse "123";;
val it : System.Numerics.BigInteger = 123 {IsEven = false;
                                           IsOne = false;
                                           IsPowerOfTwo = false;
                                           IsZero = false;
                                           Sign = 1;}
> int.Parse "123";;
  int.Parse "123";;
  ----^^^^^
error FS0039: The field, constructor or member 'Parse' is not defined.

Could somebody explain why int and bigint don’t work as I expected?

Hi @bangjunyoung.

The difference is that int is a function that converts something to the type integer, not the type itself. This is why it doesnt have the Parse method. To get that method, open System and use Int32.Parse.

In contrast, bigint is an alias for System.Numerics.BigInteger, which is why it does have the parse method. When you use bigint 6, or similar, you are actually invoking the BigInteger constructor which takes a single numeric type - its identical to new bigint(6). There is no constructor on bigint that takes a string, hence your error.

Given that int is also used as an alias for int in type signatures, I can appreciate the confusion. As bigint is used much less commonly than int, its probably understandable it is not as “standardised” as the other types.

It might also be worth adding that a bigint in SQL Server is the same a int64 in F#

A bigint in F# can hold more that 64 bits.

Thanks for making it clear. :100:

Isn’t there any chance that bigint as a function would be included in the Core library? And int as an alias in that respect as well.

Possibly, but you would have to take that up with the language suggestions.

I think unlikely since bigints are not really supposed to be used unless you have an absolute need for them - they’re designed when you need no real upper limit on your number size, like if you wanted to calculate 1000! (which results in a number with over 2000 digits). Normal programs should be fine with int, int64, unsigned int 64 etc.