1
我剛剛開始使用F#並嘗試了問題歐拉問題#3。要查找的素數,我想出了下面的代碼來計算所有素數最多數量:這個函數爲什麼說「只有簡單的變量模式可以綁定在'let rec'結構中」?
let rec allPrimes foundPrimes, current, max =
// make sure the current number isn't too high
// or the current number isn't divisible by any known primes
if current >= max then
foundPrimes
else
let nextValue = current + 1
if not List.exists (fun x -> current % x = 0L) foundPrimes then
allPrimes foundPrimes nextValue max
else
allPrimes (foundPrimes :: current) nextValue max
不幸的是,這給出了錯誤:
Only simple variable patterns can be bound in 'let rec' constructs
爲什麼會出現這個錯誤?
哦......對! woops :) – KallDrexx