Seq.generate 未定义 - 这是否已弃用?
我正在尝试测试 Beginning F# 书中的一些 F# 代码,但在引用“Seq.generate”时出现“未定义”错误。 (我正在使用 VS2010 - 所以这可能适用于 VS/F# 的早期 vn)
FWIW 我还安装了 F# Powerpack dll,但这似乎没有什么区别。
这里有解决方法/替代方法吗?
/// execute a command using the Seq.generate
let execCommand (connName: string) (cmdString: string) =
Seq.generate
// This function gets called to open a connection and create a reader
(fun () -> openConnectionReader connName cmdString)
// This function gets called to read a single item in
// the enumerable for a reader/connection pair
(fun reader -> readOneRow(reader))
(fun reader -> reader.Dispose())
I'm trying to test some F# code from the Beginning F# book but am getting 'not defined' error with the reference to 'Seq.generate'. (I'm using VS2010 - so this may have worked with earlier vn of VS/F#)
FWIW I've also installed the F# Powerpack dll, but that does not seem to make a difference.
Is there a workaround/alternative here?
/// execute a command using the Seq.generate
let execCommand (connName: string) (cmdString: string) =
Seq.generate
// This function gets called to open a connection and create a reader
(fun () -> openConnectionReader connName cmdString)
// This function gets called to read a single item in
// the enumerable for a reader/connection pair
(fun reader -> readOneRow(reader))
(fun reader -> reader.Dispose())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绝对可以使用 F# PowerPack 中的
Seq.generate
(通过引用它,或者更简单地通过从源代码复制它)。我认为该函数已被删除,因为您现在可以使用use
关键字处理对象的处理。使用
readOneRow
函数编写此代码需要使用可变状态,但您可能可以使用如下方式重写它:use
关键字正确处理读取器,这样就完成了自动为您服务。Seq.generate
函数非常好,但我认为在大多数情况下显式编写相同的内容可能更具可读性。 (特别是如果您没有在其他地方使用readOneRow
)。You can definitely use
Seq.generate
from the F# PowerPack (either by referencing it, or more easily just by copying it from the source). I think that the function was removed because you can now handle disposal of objects using theuse
keyword.Writing this using the
readOneRow
function would require using mutable state, but you can probably rewrite it by using something like this:The
use
keyword properly disposes of the reader, so that's done automatically for you. TheSeq.generate
function is quite nice, but I think that writing the same thing explicitly is probably more readable most of the time. (Especially if you're not usingreadOneRow
anywhere else).生成可以在FSharp.PowerPack.Compatibility中找到:Compat .Seq.fs
generate can be found in FSharp.PowerPack.Compatibility:Compat.Seq.fs