如何修复此F#3.0报价错误

时间:2013-06-03 13:53:14

标签: f# f#-3.0

我下载了一个Github项目,在VS 2012中打开它后,进行了自动升级。我收到一个我不明白的错误。它与报价有关。

这是我复制粘贴的文件:https://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/blob/master/Chapter%2012%20-%20BindingMicroDSL/BindingMicroDSL/StockPricesChart.fs

错误“报价可能不涉及对捕获的本地变量的分配或获取地址”

违规代码是此键和值:

this.Control.DetailsName, <@@ stockProperty.Key @@>

this.Control.DetailsValue, <@@ stockProperty.Value @@>

namespace FSharp.Windows.Sample

open System.Windows.Data
open System.Drawing
open System.Windows.Forms.DataVisualization.Charting
open System.Collections.ObjectModel

open FSharp.Windows
open FSharp.Windows.UIElements

[<AbstractClass>]
type StockPricesChartModel() = 
    inherit Model()

    abstract StocksInfo : ObservableCollection<StockInfoModel> with get, set
    abstract SelectedStock : StockInfoModel with get, set

type StockPricesChartView(control) as this =
    inherit PartialView<unit, StockPricesChartModel, StockPricesChartControl>(control)

    do 
        let area = new ChartArea() 
        area.AxisX.MajorGrid.LineColor <- Color.LightGray
        area.AxisY.MajorGrid.LineColor <- Color.LightGray        
        this.Control.StockPricesChart.ChartAreas.Add area
        let series = 
            new Series(
                ChartType = SeriesChartType.Column, 
                Palette = ChartColorPalette.EarthTones, 
                XValueMember = "Symbol", 
                YValueMembers = "LastPrice")
        this.Control.StockPricesChart.Series.Add series

    override this.EventStreams = 
        [
            this.Control.AddStock.Click |> Observable.mapTo()
        ]

    override this.SetBindings model = 
        this.Control.StockPricesChart.DataSource <- model.StocksInfo
        model.StocksInfo.CollectionChanged.Add(fun _ -> this.Control.StockPricesChart.DataBind())

        this.Control.Symbol.SetBindings(
            itemsSource = <@ model.StocksInfo @>, 
            selectedItem = <@ model.SelectedStock @>,
            displayMember = <@ fun m -> m.Symbol @> 
        )

        this.Control.Details.SetBindings(
            itemsSource = <@ model.SelectedStock.Details @>, 
//////////////////            OFFENDING CODE    ///////////////////
            columnBindings = fun stockProperty ->
                [
                    this.Control.DetailsName, <@@ stockProperty.Key @@>
                    this.Control.DetailsValue, <@@ stockProperty.Value @@>
                ]
        )

type StockPricesChartController() = 
    inherit Controller<unit, StockPricesChartModel>()

    override this.InitModel model = 
        model.StocksInfo <- ObservableCollection()

    override this.Dispatcher = fun() -> 
        Async <| fun model ->
            async {
                let! result = Mvc.startWindow(StockPickerView(), StockPickerController())  
                result |> Option.iter(fun newItem -> 
                    model.StocksInfo.Add newItem
                    model.SelectedStock <- newItem
                )
            }

1 个答案:

答案 0 :(得分:5)

这是F#3.0的突破 http://msdn.microsoft.com/en-us/library/hh416791.aspx 正如Leaf Garland指出的那样,它不是你问题的直接答案,而是看看升级到VS 2012代码https://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/wiki/Visual-Studio-2012