Take the 2-minute tour ×

How add key-value pair to instance on HashMultiMap that is member of declared by the user type? maybe I'm doing something wrong

    type Test() = 
        member this.tmp = new HashMultiMap<string, int>(HashIdentity.Structural)
        member this.add name test = 
            this.tmp.Add(name, test)
    let t1 = new Test()
    t1.add "aaa" 1
    let a1 = t1.tmp.TryFind("aaa")
    let b1 = t1.tmp.Count
    let t2 = new HashMultiMap<string, int>(HashIdentity.Structural)
    t2.Add("aaa", 1)
    let a2 = t2.TryFind("aaa")
    let b2 = t2.Count


--> Referenced 'C:\Program Files\FSharpPowerPack-\bin\FSharp.PowerPack.dll'

type Test =
    new : unit -> Test
    member add : name:string -> test:int -> unit
    member tmp : HashMultiMap<string,int>
val t1 : Test
val a1 : int option = None
val b1 : int = 0
val t2 : HashMultiMap<string,int>
val a2 : int option = Some 1
val b2 : int = 1
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Every time you call this.tmp you create a new multimap - you want to use

type Test() = 
    let map =  new HashMultiMap<string, int>(HashIdentity.Structural)
    member this.tmp = map
    member this.add name test = 
        map.Add(name, test)

note that new is only called once

share|improve this answer
add comment

Your Answer


