anchor.diff:    let collectSeq (f: 'T -> AsyncSeq<'U>) (inp: seq<'T>) : AsyncSeq<'U> = 
           { new IAsyncEnumerable<'U> with 
                 member x.GetEnumerator() = 
  -                  let state = ref -1
  -                  // state -1: not started
  -                  // state 0: have input enumerator, do not yet have inner enumerator
  -                  // state 1: have input enumerator and inner enumerator
  -                  // state 2: finished input enumerator
  -                  // state 3: finished 
  +                  let state = ref CollectState.NotStarted
                     let enum1 = ref Unchecked.defaultof<System.Collections.Generic.IEnumerator<'T>>
                     let enum2 = ref Unchecked.defaultof<IAsyncEnumerator<'U>>
                     { new IAsyncEnumerator<'U> with 
                           member x.MoveNext() = 
                               async { match !state with 
  -                                    | -1 -> 
  +                                    | CollectState.NotStarted -> 
                                           return! 
                                              (enum1 := inp.GetEnumerator()
  -                                            state := 0
  +                                            state := CollectState.HaveInputEnumerator
                                               x.MoveNext())
  -                                    | 0 ->   
  +                                    | CollectState.HaveInputEnumerator ->   
                                           return! 
                                             (let e1 = enum1.Value
                                              if e1.MoveNext()  then 
                                                  enum2 := (f e1.Current).GetEnumerator()
  -                                               state := 1
  +                                               state := CollectState.HaveInnerEnumerator
                                              else
  -                                               state := 2
  +                                               x.Dispose()
                                              x.MoveNext())
  -                                    | 1 ->   
  +                                    | CollectState.HaveInnerEnumerator ->   
                                           let e2 = enum2.Value
                                           let! res2 = e2.MoveNext() 
                                           match res2 with 
                                           | None ->
                                               return! 
                                                 (enum2 := Unchecked.defaultof<_>
  -                                               state := 0
  +                                               state := CollectState.HaveInputEnumerator
                                                  dispose e2
                                                  x.MoveNext())
                                           | Some _ -> 
                                               return res2
  -                                    | 2 -> 
  -                                        return None
  -                                    | _ -> 
  -                                        return! invalidOp "enumerator already finished" }
  +                                    | _ -> return None}
                           member x.Dispose() = 
                               match !state with 
  -                            | 0 -> 
  -                                let e = enum1.Value
  -                                state := 3
  +                            | CollectState.HaveInputEnumerator -> 
  +                                let e1 = enum1.Value
  +                                state := CollectState.Finished
                                   enum1 := Unchecked.defaultof<_>
  -                                dispose e 
  -                            | 1 -> 
  -                                let e2 = enum1.Value
  -                                state := 0
  +                                dispose e1 
  +                            | CollectState.HaveInnerEnumerator -> 
  +                                let e2 = enum2.Value
  +                                state := CollectState.HaveInputEnumerator
                                   dispose e2
                                   x.Dispose()
                               | _ -> () } }
   
  +  type MapState =
  +     | NotStarted    = -1
  +     | HaveEnumerator = 0
  +     | Finished = 1
  +
     let ofSeq (inp: seq<'T>) : AsyncSeq<'T> = 
           { new IAsyncEnumerable<'T> with 
                 member x.GetEnumerator() = 
  -                  let state = ref -1
  -                  // state -1: not started
  -                  // state 0: have input enumerator
  -                  // state 1: finished 
  +                  let state = ref MapState.NotStarted
                     let enum = ref Unchecked.defaultof<System.Collections.Generic.IEnumerator<'T>>
                     { new IAsyncEnumerator<'T> with 
                           member x.MoveNext() = 
                               async { match !state with 
  -                                    | -1 -> 
  +                                    | MapState.NotStarted -> 
                                           enum := inp.GetEnumerator()
  -                                        state := 0
  +                                        state := MapState.HaveEnumerator
                                           return! x.MoveNext()
  -                                    | 0 ->   
  +                                    | MapState.HaveEnumerator ->   
                                           let e1 = enum.Value
  -                                        if e1.MoveNext()  then 
  -                                            return Some enum.Value.Current
  -                                        else 
  -                                            enum := Unchecked.defaultof<_>
  -                                            dispose e1
  -                                            state := 1
  -                                            return None
  -                                    | 1 ->   
  -                                        return None
  -                                    | _ -> 
  -                                        return! invalidOp "unreachable" }
  +                                        return 
  +                                            (if e1.MoveNext()  then 
  +                                                 Some e1.Current
  +                                             else 
  +                                                 x.Dispose()
  +                                                 None)
  +                                    | _ -> return None }
                           member x.Dispose() = 
                               match !state with 
  -                            | 0 -> 
  +                            | MapState.HaveEnumerator -> 
                                   let e = enum.Value
  -                                state := 1
  +                                state := MapState.Finished
                                   enum := Unchecked.defaultof<_>
                                   dispose e 
                               | _ -> () } }
  
positive.code:                                         return None }
                          member x.Dispose() = 
                              match !state with 
                              | 0 -> 
                                  let e = enum.Value
                                  state := 1
                                  enum := Unchecked.defaultof<_>
                                  dispose e 
                              | _ -> () } }
  
negative.code: 
  
    let delay (f: unit -> AsyncSeq<'T>) : AsyncSeq<'T> = 
        { new IAsyncEnumerable<'T> with 
            member x.GetEnumerator() = f().GetEnumerator() }
  
  
    type BindState =
       | NotStarted     = -1
       | HaveEnumerator = 0
       | Finished        = 1
  
    let bindAsync (f: 'T -> AsyncSeq<'U>) (inp : Async<'T>) : AsyncSeq<'U> = 
          { new IAsyncEnumerable<'U> with 
                member x.GetEnumerator() = 
                    let state = ref BindState.NotStarted
                    let enum = ref Unchecked.defaultof<IAsyncEnumerator<'U>>
                    { new IAsyncEnumerator<'U> with 
                          member x.MoveNext() = 
                              async { match !state with 
                                      | BindState.NotStarted -> 
                                          let! v = inp 
                                          return! 
                                             (let s = f v
                                              let e = s.GetEnumerator()
                                              enum := e
                                              state := BindState.HaveEnumerator
                                              x.MoveNext())
                                      | BindState.HaveEnumerator ->   
                                          let! res = enum.Value.MoveNext() 
                                          return (match res with
                                                  | None -> 
  