在记录f#中作为属性添加到地图

时间:2018-10-21 19:09:32

标签: dictionary types f# functional-programming

我有这种类型:

type Model = {Ships: map<Mmsi, Ship>}
type Ship = {Latitude: float Longitude: float Speed: float Heading: float}

我正在尝试找到一种通过消息类型添加到飞船地图的方法

type msg = {Latitude: float Longitude: float Mmsi = int Time = string}

使用此功能:

let update (msg : Msg) (currentModel : Model) : Model =
    // TODO: implement the new model based on the received message here
    let currentModel = 
        { 
            Ships = Map.Add(msg.Mmsi, msgToShip msg)
        }
    currentModel

但是我从编译器中得到了这样的错误:“方法或对象构造函数'Add'不是静态的。

一般来说,我在f#或函数式编程方面没有特别的经验,因此,对此的任何指点将不胜感激。

1 个答案:

答案 0 :(得分:0)

大写的itemName(type:any){ this.items = this.db.list(`items/${type}`).valueChanges(); return this.items; } 是类型Add的实例方法。小写的Map<_, _>add模块中的函数。所以您想在这里打电话的是:

Map

或者,也有效,但不太习惯:

Ships = Map.add msg.Mmsi (msgToShip msg) currentModel.Ships