下好了,这是相当令人沮丧,我,已经安装了最新版本的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