Perché F # non è possibile dedurre il tipo di questa affermazione?
-
21-08-2019 - |
Domanda
/// 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)
Soluzione
costruttori della classe non possono essere utilizzati senza argomenti. È possibile scrivere
let max = float n |> sqrt |> int64 |> (fun x -> Math.BigInt(x))
se ti piace. (Lì per lì non so il motivo di questa limitazione, però.)
Altri suggerimenti
Nella mia versione di F # (1.9.4.19 su Mono), entrambe le versioni falliscono con:
The member or object constructor 'BigInt' takes 0 argument(s) but is here given 1. The required signature is 'Math.BigInt()'.
posso usare
let max = float n |> sqrt |> int64 |> Math.BigInt.of_int64
per ottenere un bigint
o
let max = float n |> sqrt |> int64 |> Math.BigInt.FromInt64
per ottenere un Math.BigInt
.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow