IEnumerable <t> cant枚举或不兼容seq <t> </t> </t>

时间:2013-12-18 19:30:13

标签: .net f#

我是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'

出了什么问题,这应该像我所说的一样。

1 个答案:

答案 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]
相关问题