gpt4 book ai didi

F# 静态成员

转载 作者:行者123 更新时间:2023-12-03 15:08:27 25 4
gpt4 key购买 nike

我正在浏览 PDC 2008 F# 视频,但似乎遇到了问题

type StockAnalyzer (lprices, days) =
let prices =
lprices
|> Seq.map snd
|> Seq.take days
static member GetAnalyzers(tickers, days) =
tickers
|> Seq.map loadPrices
|> Seq.map (fun prices -> new StockAnalyzer(prices, days))

member s.Return =
let lastPrice = prices |> Seq.nth 0
let startPrice = prices |> Seq.nth (days - 1)
lastPrice / startPrice - 1.

我在静态时遇到错误。
GetStockPrices.fs(31,6): error FS0010: Unexpected keyword 'static' in binding. Expected incomplete structured construct at or before this point or other token.

有谁知道他们是否更改了语法或可以发现我做错了什么

最佳答案

F# 使用大量空白。在“让价格=”前加一个空格。编译器试图弄清楚为什么你有一个“价格”的静态成员,因为唯一缩进较少的前一行是“让价格=”。

您可能想要使用更多的缩进,只是为了清楚起见。

type StockAnalyzer (lprices, days) =
let prices =
lprices
|> Seq.map snd
|> Seq.take days

static member GetAnalyzers(tickers, days) =
tickers
|> Seq.map loadPrices
|> Seq.map (fun prices -> new StockAnalyzer(prices, days))

member s.Return =
let lastPrice = prices |> Seq.nth 0
let startPrice = prices |> Seq.nth (days - 1)
lastPrice / startPrice - 1.

关于F# 静态成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2398510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com