F # forward pipe to convert from int to bigint

I am new to F # and approached this scenario and hoped that someone could explain why my compiler does not like code ...

If in F # I do the following ...

let FloatToInt = 10.0 |> int let IntToFloat = 10 |> float 

Everything is in order and the number is passed to the corresponding data type ...

if, however, I do the following ...

 let IntToBigInt = 10 |> bigint 

I get the error "Invalid use of type name or object constructor". I assume this is because there is no operator overload for the direct channel for bigint?

If I wanted to make this code possible, how would I do it? I know I can use a different syntax, for example ...

 let IntToBigInt = bigint(10) 

But I really like the Forward Pipe syntax and would like to know if I can achieve it to ...

 let IntToBigInt = 10 |> bigint 

will work...

+6
f #
source share
1 answer

This has nothing to do with congestion. 10.0 |> int works because there is a function called int . However, there is no function named bigint , so 10 |> bigint does not work.

If you define one, it works:

 > let bigint (x:int) = bigint(x);; // looks recursive, but isn't val bigint : int -> System.Numerics.BigInteger > 42 |> bigint;; val it : System.Numerics.BigInteger = 42I 
+14
source share

All Articles