下好了,這是相當令人沮喪,我,已經安裝了最新版本的SharpDevelop的,並且還安裝了F#編譯器(按從SharpDevelops網站的鏈接)F#的SharpDevelop
我在Vista上運行。
到目前爲止,一切都工作正常。
但由於某些原因,它只是拒絕編譯時,我嘗試使用List.fold_left,但是List.fold似乎工作,
這裏是錯誤:
The value, constructor, namespace or type 'fold_left' is not defined (FS0039)
這裏是代碼:
#light
open System
let nums = [1..10]
let ans = List.fold_left (+) 0 nums
Console.WriteLine("answer: {0}", ans)
// Just to make it pause
let pause = Console.ReadLine()
進一步的問題是,我試圖用摺疊列表如方的每個項目:
1^2 + 2^2 + 3^2 ...
我假定折取一個函數和一個列表,所以我已經試過如下:
let sq x = x*x
let ans = List.fold (sq) 0 nums
,但是這給了我下面的錯誤都在第二行:
The type 'int -> int' does not match the type 'int' (FS0001) - The type ''a -> int' does not match the type 'int' (FS0001) -
請有人可以解釋這一點?
因此,這引起了我前幾天想知道的事情。標準庫中是否有正確的摺疊? – 2010-07-01 03:05:10
@Nels - 是的,它被稱爲'List.foldBack'。 – kvb 2010-07-01 03:21:30
你可以通過查看我在我的答案中鏈接的文檔來找到它。圖書館文件是一個體面的參考 - 看看! – Brian 2010-07-01 04:43:16