anchor.diff:          r.AddOutput res
           res
   
  +
       let reduceM (f : seq<'a> -> 'b) (s : aset<IMod<'a>>) : IMod<'b> =
  -        s |> toMod |> Mod.bind (Mod.mapN f)
  +        reduce f (collect ofMod s)
   
       let foldSemiGroupM (add : 'a -> 'a -> 'a) (zero : 'a) (s : aset<IMod<'a>>) : IMod<'a> =
  -        let r = s.GetReader()
  -        let sum = ref zero
  -
  -        let res = ref Unchecked.defaultof<_>
  -        res :=
  -            Mod.custom (fun () ->
  -                let mutable rem = false
  -                let delta = r.GetDelta()
  -                for d in delta do
  -                    match d with
  -                        | Add v -> 
  -                            v.AddOutput !res
  -                            sum := add !sum (v.GetValue())
  -                        | Rem v -> 
  -                            v.RemoveOutput !res
  -                            rem <- true
  -
  -                if rem then
  -                    sum := r.Content |> Seq.fold (fun s v -> add s (v.GetValue())) zero
  -
  -                !sum
  -            )
  -
  -        r.AddOutput !res
  -        !res
  +        let s = s |> collect ofMod
  +        foldSemiGroup add zero s
   
       let foldGroupM (add : 'a -> 'a -> 'a) (sub : 'a -> 'a -> 'a) (zero : 'a) (s : aset<IMod<'a>>) : IMod<'a> =
  -        let r = s.GetReader()
  -        let sum = ref zero
  -
  -        let res = ref Unchecked.defaultof<_>
  -        res :=
  -            Mod.custom (fun () ->
  -                let delta = r.GetDelta()
  -                for d in delta do
  -                    match d with
  -                        | Add v -> 
  -                            v.AddOutput !res
  -                            sum := add !sum (v.GetValue())
  -                        | Rem v -> 
  -                            v.RemoveOutput !res
  -                            sum := sub !sum (v.GetValue())
  -                !sum
  -            )
  -
  -        r.AddOutput !res
  -        !res
  +        let s = s |> collect ofMod
  +        foldGroup add sub zero s
   
   
       let inline sum (s : aset<'a>) = foldGroup (+) (-) LanguagePrimitives.GenericZero s
  
positive.code:         r.AddOutput m
          m
  
      let contains (elem : 'a) (set : aset<'a>) =
          set |> toMod |> Mod.map (fun s -> s.Contains elem)
  
      let containsAll (elems : #seq<'a>) (set : aset<'a>) =
          set |> toMod |> Mod.map (fun s -> elems |> Seq.forall (fun e -> s.Contains e))
  
      let containsAny (elems : #seq<'a>) (set : aset<'a>) =
          set |> toMod |> Mod.map (fun s -> elems |> Seq.exists (fun e -> s.Contains e))
  
  
      let map (f : 'a -> 'b) (set : aset<'a>) = 
          let scope = Ag.getContext()
          AdaptiveSet(fun () -> set.GetReader() |> map scope f) :> aset<'b>
  
      let bind (f : 'a -> aset<'b>) (m : IMod<'a>) =
          let scope = Ag.getContext()
          AdaptiveSet(fun () -> m |> bind scope (fun v -> (f v).GetReader())) :> aset<'b>
  
      let bind2 (f : 'a -> 'b -> aset<'c>) (ma : IMod<'a>) (mb : IMod<'b>) =
          let scope = Ag.getContext()
          AdaptiveSet(fun () -> bind2 scope (fun a b -> (f a b).GetReader()) ma mb) :> aset<'c>
  
  
      let collect (f : 'a -> aset<'b>) (set : aset<'a>) = 
          let scope = Ag.getContext()
          AdaptiveSet(fun () -> set.GetReader() |> collect scope (fun v -> (f v).GetReader())) :> aset<'b>
  
      let choose (f : 'a -> Option<'b>) (set : aset<'a>) =
          let scope = Ag.getContext()
          AdaptiveSet(fun () -> set.GetReader() |> choose scope f) :> aset<'b>
  
      let filter (f : 'a -> bool) (set : aset<'a>) =
          choose (fun v -> if f v then Some v else None) set
  
      let concat (set : aset<aset<'a>>) =
          collect id set
  
  
negative.code:     let foldSemiGroup (add : 'a -> 'a -> 'a) (zero : 'a) (s : aset<'a>) : IMod<'a> =
          let r = s.GetReader()
          let sum = ref zero
  
          let rec processDeltas (deltas : list<Delta<'a>>) =
              match deltas with
                  | Add v :: deltas ->
                      sum := add !sum v
                      processDeltas deltas
                  | Rem v :: deltas ->
                      false
                  | [] ->
                      true
  
          let res =
              Mod.custom (fun () ->
                  let mutable rem = false
                  let delta = r.GetDelta()
  
                  if not <| processDeltas delta then
                      sum := r.Content |> Seq.fold add zero
  
                  !sum
  