/// I can't do this
let max = float n |> sqrt |> int64 |> Math.BigInt
/// But this is allowed
let max = Math.BigInt(float n |> sqrt |> int64)
views:
316answers:
2
+3
A:
Class constructors cannot be used without arguments. You can write
let max = float n |> sqrt |> int64 |> (fun x -> Math.BigInt(x))
if you like. (Offhand I don't know the reason for this restriction, though.)
Brian
2009-05-11 03:43:42
Is int64 a class?
Unknown
2009-05-11 03:51:29
No, in this context it's a function defined in http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/FSharp.Core/Microsoft.FSharp.Core.Operators.html
Brian
2009-05-11 05:14:35
Also can you tell me where to find the square root for a BigInt?
Unknown
2009-05-11 05:15:08
There is no Sqrt function defined for BigInt in the library.
Brian
2009-05-11 06:08:52
@Brian do you know if there will be one?
Unknown
2009-05-11 07:28:43
No, I don't think one is planned for .Net 4.0's System.Numerics.BigInteger. You can always author your own.
Brian
2009-05-11 12:08:44
A:
In my version of F# (1.9.4.19 on Mono), both versions fail with:
The member or object constructor 'BigInt' takes 0 argument(s) but is here given 1. The required signature is 'Math.BigInt()'.
I can use
let max = float n |> sqrt |> int64 |> Math.BigInt.of_int64
to get a bigint
or
let max = float n |> sqrt |> int64 |> Math.BigInt.FromInt64
to get a Math.BigInt
.
Chris Conway
2009-05-11 14:33:59