我正在使用
通过尝试以下示例代码 https://github.com/tpetricek/Documents/tree/master/Samples/Twitter.API 我想要扩展推文中的 URL。
这将导致错误:
我的问题是如何为上述
类型推断显示了以下结果。
FSharp.Data.JsonProvider
来读取 Twitter 推文。通过尝试以下示例代码 https://github.com/tpetricek/Documents/tree/master/Samples/Twitter.API 我想要扩展推文中的 URL。
let expandUrl (txt:string) (url:Search.DomainTypes<...>.DomainTypes.Url) =
txt.Replace( url.Url, url.ExpandedUrl )
这将导致错误:
Lookup on object of indeterminate type based on information prior to this program point.
A type annotation may be needed prior to this program point to constrain the type of the object.
我的问题是如何为上述
expandUrl
函数中的 URL 定义 TypeProvider
类型?类型推断显示了以下结果。
val urls : FSharp.Data.JsonProvider<...>.DomainTypes.Url []
但是这在类型声明中是不被接受的。我认为"<...>"不是F#语法。
如何对使用TypeProvider类型进行类型注释,例如FSharp.Data.JsonProvider<...>.DomainTypes.Url
?
以下是完整的代码片段:
open TwitterAPI // github.com/tpetricek/Documents/tree/master/Samples/Twitter.API
let twitter = TwitterAPI.TwitterContext( _consumerKey, _consumerSecret, _accessToken, _accessTokenSecret )
let query = "water"
let ts = Twitter.Search.Tweets(twitter, Utils.urlEncode query, count=100)
let ret =
[ for x in ts.Statuses do
// val urls : FSharp.Data.JsonProvider<...>.DomainTypes.Url []
let urls = x.Entities.Urls
// fully declarated to help the type inference at expandUrl
let replace (txt:string) (oldValue:string) (newValue:string) =
txt.Replace( oldValue, newValue)
// Error:
// Lookup on object of indeterminate type based on information prior to this program point.
// A type annotation may be needed prior to this program point to constrain the type of the object.
// This may allow the lookup to be resolved.
let expandUrl (txt:string) (url:FSharp.Data.JsonProvider<_>.DomainTypes.Url) =
replace txt url.Url url.ExpandedUrl
let textWithExpandedUrls = Array.fold expandUrl x.Text urls
yield textWithExpandedUrls
]