I’m writing an F# function that factorises a number into prime factors.
let factors primes i =
let mutable j = i
for p in primes do
while (j>1) && (j%p=0) do
j <- j/p
printfn "prime: %i" p
It works for int values of i, but not int64 values. The parameter primes is a set of int values.
I understand why this is the case – type inference is assuming that the function only takes int parameters – but I want to explicitly specify the parameter type as int64.
Is it possible to write this function so that it will work for both int and int64?
If you want to work only on
int64values, just replace1and0with1Land0Lrespectively. jpalmer’s answer covers the generic case.