我对F#非常陌生,所以我可能在这里使用了错误的术语。如果我错了,请随时纠正我,我将不胜感激!
我有一个记录,我已经这样定义了:
type EventSource = {
SourceName: string
Address: string
ParseDocument: HtmlDocument -> Event seq }
let lofSource = {
SourceName = "LOF"
Address = "https://lof.dk/syd/kurser"
ParseDocument = fun document ->
document.Descendants ["div"]
|> Seq.filter (fun d -> d.HasClass("item"))
|> Seq.map (
fun e ->
let linkElement
= e.Descendants (fun j -> j.HasClass "item-title")
|> Seq.head
|> (fun y -> y.Descendants ["a"])
|> Seq.map (fun fa -> fa.Attribute "href")
|> Seq.head
{
Title = e.AttributeValue "data-holdnavn"
Link = linkElement.Value()
Status = e.AttributeValue "data-status"
Image = Address //Here!
City = e.AttributeValue "data-bynavn"
Date = System.DateTime.ParseExact(e.AttributeValue("data-datosort"), "yyyyMMdd", null);
PostalCode = e.AttributeValue("data-postnr")})
}
在我试图为Image成员赋值的那一行,它告诉我没有定义值或构造函数'Address‘。
我尝试在记录的实例化中使用自我标识符,然后尝试访问如下地址
this.Address
发布于 2019-06-12 03:06:38
你不能用记录做到这一点。请参阅:Reference a record from within itself during construction
您可以使用另一个绑定(我无法编译您的代码,因此对其进行了简化):
type EventSource = {
SourceName: string
Address: string
ParseDocument: string -> string}
let lofSource =
let helloThere = "General Kenobi"
{
SourceName = "LOF"
Address = foo
ParseDocument = fun document ->
foo
}
https://stackoverflow.com/questions/56549890
复制相似问题