我是F#的新手,但Seq应该和IEnumerable一样吗?
let test = makeAsyncRequestPage "some web page"
|> Async.RunSynchronously
|> getPageResult //Returns a Seq<HtmlNode>
|> Seq.head<HtmlNode>
|> fun h -> h.ChildNodes.Nodes //IEnumerable<HtmlNode>
|> fun h -> [for row in h -> row]
运行代码时出错,h
是IEnumerable,出现以下错误:
'The type '(unit -> System.Collections.Generic.IEnumerable<HtmlNode>)' is not a type whose values can be enumerated with this syntax, i.e. is not compatible with either seq<_>, IEnumerable<_> or IEnumerable and does not have a GetEnumerator method'
出了什么问题,这应该像我所说的一样。
答案 0 :(得分:4)
h.ChildNodes.Nodes
是一种方法,因此您需要应用unit
参数:
let test = makeAsyncRequestPage "some web page"
|> Async.RunSynchronously
|> getPageResult //Returns a Seq<HtmlNode>
|> Seq.head<HtmlNode>
|> fun h -> h.ChildNodes.Nodes ()
|> fun h -> [for row in h -> row]