I was working through the PDC 2008 F# videos and seem to run into a problem
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.
I am getting an error at the static.
GetStockPrices.fs(31,6): error FS0010: Unexpected keyword 'static' in binding. Expected incomplete structured construct at or before this point or other token.Does anyone know if they have changed the syntax or can spot what I am doing wrong
F# uses significant white space. Add a space in front of "let prices =". The compiler is trying to figure out why you have a static member of "prices", because the only preceding line with less indentation is "let prices =".
You may want to use more indentation, just for clarity.
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.
The indentation before the word static
is confusing the compiler and it's trying to interpret it as part of the let
expression. The let
expression should be indented and the member definitions should be in line with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With