title: How to write an immutable TallySet (counting multiset) in FSharp
body: <p>I am trying to create an immutable collection type that behaves  as a hybrid
  of multiset/bag and Map that records the number of occurrences of each item.</p>
  
  <p>I can write a mutable one with code a little like below and I tried to write an immutable one by inheriting from Map but Map is sealed and will not let me define any overrides.  </p>
  
  <pre><code>type TallySet&lt;'k_t when 'k_t : comparison&gt;() = class
      //    inherit Map&lt;'k_t, int&gt;
      let m_map:((Map&lt;'k_t, int&gt;) ref) = ref (Map.empty)
  
      member x.add item =
          m_map :=
              match (!m_map).TryFind item with
                  | None -&gt; (!m_map).Add(item, 1)
                  | Some n -&gt; (!m_map).Add(item, 1 + n)
         !m_map
  
      member x.Count with get() = Map.fold (fun cc k v -&gt; cc + v) 0 !m_map
  end
  </code></pre>
  
  <p>What should I write ?</p>