Static member F #

I was working on the PDC 2008 F # footage and it seems to have 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 get an error in static.

GetStockPrices.fs (31.6): error FS0010: Unexpected keyword "static" in binding. The expected incomplete structured construction to or to this point or another token.
Does anyone know if they have changed the syntax or can determine what I am doing wrong.
+4
source share
2 answers

F # uses a significant space. Add space in front of "let prices =". The compiler is trying to understand why you have a static member of "prices" because the only previous line with less indentation is "let prices =".

You can 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. 
+13
source

The indentation of the word static confuses the compiler and attempts to interpret it as part of the let statement. The let expression must be indented, and the definitions of members must match it.

+6
source

Source: https://habr.com/ru/post/1303421/


All Articles