anchor.diff:      let mutable linkedErrorRemoves: IDisposable list = []
       let mutable protocolLogSubscriptions: IDisposable list = []
       let logSource = LogSource.Actor name
  -    let linkedActors = defaultArg linkedActors Seq.empty
  +    let linkedActors = match linkedActors with None -> [||] | Some la -> Seq.toArray la
       let logEvent = new Event<Log>()
       let primaryProtocol = protocols.[0] :?> IPrimaryProtocolServer<'T>
       let clientProtocols = protocols |> Array.map (fun protocol -> protocol.Client)
  
positive.code:                 override actor.Ref = actorRef
          }
  
      let spawnMany (processFunc: 'T -> Async<unit>) (howMany: int) (balancer: seq<ActorRef<'T>> -> ActorRef<'T>): Actor<'T> =
          [ for i in 1..howMany -> spawn processFunc ] |> balance balancer
  
      let box (actor: Actor<'T>): Actor<obj> =
          actor |> map (fun msg -> msg :?> 'T)
  
      let unbox (actor: Actor<obj>): Actor<'T> =
          actor |> map (fun msg -> msg :> obj)
  
      let union (actor: Actor<'T>) (actor': Actor<'U>): Actor<Choice<'T, 'U>> =
          spawnLinked (fun msg -> async {
              match msg with
              | Choice1Of2 m -> !actor <-- m
              | Choice2Of2 m -> !actor' <-- m
          }) [actor |> box; actor' |> box]
  
  [<AutoOpen>]
  module ActorRefExtensions =
      module ActorRef =
          let inline configurationFilter (filterF: IProtocolFactory -> bool) (actorRef: ActorRef<'T>): ActorRef<'T> = actorRef.ProtocolFilter filterF
          let inline empty() = Actor.sink() |> Actor.ref
  
  module Behavior =
      module WithSelf =
          let rec stateful (state: 'U) (behavior: 'U -> ActorRef<'T> -> 'T -> Async<'U>) (self: Actor<'T>) =
              async {
                  let! msg = self.Receive()
  
                  let! state' = behavior state !self msg
  
                  return! stateful state' behavior self
              }
  
          let stateless (behavior: ActorRef<'T> -> 'T -> Async<unit>) =
              stateful () (fun _ self msg -> behavior self msg)
        
      let rec stateful (state: 'U) (behavior: 'U -> 'T -> Async<'U>) = WithSelf.stateful state (fun state _ msg -> behavior state msg)
  
      let rec stateful2 (state: 'U) (behavior: 'U -> Actor<'T> -> Async<'U>) (self : Actor<'T>) =
          async {
              let! state' = behavior state self
  
              return! stateful2 state' behavior self
          }
  
      let stateless (behavior: 'T -> Async<unit>) (self: Actor<'T>) =
          stateful () (fun _ msg -> behavior msg) self
  
negative.code:     interface IDisposable with override self.Dispose() = self.Stop()
  
  
  /// Extension methods for Actor types.
  [<AutoOpen>]
  module ActorExtensions =
      
      type Actor with
          /// <summary>
          ///     Log information event.
          /// </summary>
          /// <param name="info">info value.</param>
          member self.LogInfo<'L>(info: 'L) = self.LogEvent(Info, info)
  
          /// <summary>
          ///     Log warning event.
          /// </summary>
          /// <param name="warning">warning value.</param>
          member self.LogWarning<'L>(warning: 'L) = self.LogEvent(Warning, warning)
  
          /// <summary>
          ///     Log exception event.
          /// </summary>
          /// <param name="exn">exception value.</param>
          member self.LogError(exn : exn) = self.LogEvent(Error, exn)
   
   /// Collection of operators acting on actor types.
  [<AutoOpen>]
  module Operators =
  
      /// <summary>
      ///     Synchronously post message to actor reference.
      /// </summary>
      /// <param name="actorRef">Recipient actor.</param>
      /// <param name="msg">Message.</param>
      let inline (<--) (actorRef: ActorRef<'T>) (msg: 'T) = actorRef.Post(msg)
  
      /// <summary>
      ///     Asynchronously post message to actor reference.
      /// </summary>
      /// <param name="actorRef">Recipient actor.</param>
      /// <param name="msg">Message.</param>
      let inline (<-!-) (actorRef: ActorRef<'T>) (msg: 'T) = actorRef.AsyncPost msg
  
      /// <summary>
      ///     Synchronously post message to actor reference.
      /// </summary>
      /// <param name="actorRef">Recipient actor.</param>
      /// <param name="msg">Message.</param>
      let inline (-->) (msg: 'T) (actorRef: ActorRef<'T>) = actorRef <-- msg
  
      /// <summary>
      ///     Post message to actor reference and asynchronously await for reply.
      /// </summary>
      /// <param name="actorRef">Recipient actor.</param>
      /// <param name="msg">Message builder.</param>
      let inline (<!-) (actorRef: ActorRef<'T>) (msgF: IReplyChannel<'R> -> 'T) = actorRef.PostWithReply(msgF)
  
      /// <summary>
      ///     Post message to actor reference and asynchronously await for reply.
      /// </summary>
      /// <param name="actorRef">Recipient actor.</param>
      /// <param name="msg">Message builder.</param>
      let inline (<!=) (actorRef: ActorRef<'T>) (msgF: IReplyChannel<'R> -> 'T) = actorRef <!- msgF |> Async.RunSynchronously
  
      /// <summary>
      ///     Gets actor reference for given actor.
      /// </summary>
      /// <param name="actor">Actor to get reference from.</param>
      let inline (!) (actor: Actor<'T>): ActorRef<'T> = actor.Ref
                
  /// Collection of actor combinators
  [<RequireQualifiedAccess>]
  [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
  module Actor =
  
      /// <summary>
      ///     Instantiates an asynchronous, tail recursive actor behaviour workflow into an inactive actor instance.
      /// </summary>
      /// <param name="body">Actor behaviour workflow.</param>
      let inline bind (body: Actor<'T> -> Async<unit>) = let name = Guid.NewGuid().ToString() in new Actor<'T>(name, body)
  
      /// Creates a trivial actor that exits.
      let inline empty() : Actor<'T> = bind (fun _ -> async.Zero())
  
      // this appears to be wrong: will receive one message and then exit, should probably discard everything it receives.
  
      /// Creates a trivial actor that receives a single message and exits.
      let inline sink() : Actor<'T> = bind (fun actor -> actor.Receive() |> Async.Ignore)
  
      /// <summary>
      ///     Wraps an asynchronous reactive workflow into a tail-recursive actor definition.
      /// </summary>
      /// <param name="reactF">Worfklow that reacts on input messages.</param>
      let inline spawn (reactF: 'T -> Async<unit>) =
          let rec body (actor: Actor<'T>) = async { 
                  let! msg = actor.Receive()
                  do! reactF msg
                  return! body actor
              }
          bind body
  
      /// <summary>
      ///     Instantiates an asynchronous, tail recursive actor behaviour workflow into an inactive actor instance.
      /// </summary>
      /// <param name="body">Actor behaviour workflow.</param>
      /// <param name="linkedActors">Actors linked to current instance.</param>
      let inline bindLinked (body: Actor<'T> -> Async<unit>) (linkedActors: #seq<Actor>) = 
          new Actor<'T>(String.Empty, body, linkedActors = linkedActors)
  
      /// <summary>
      ///     Wraps an asynchronous reactive workflow into a tail-recursive actor definition.
      /// </summary>
      /// <param name="reactF">Worfklow that reacts on input messages.</param>
      /// <param name="linkedActors">Actors linked to current instance.</param>
      let inline spawnLinked (reactF : 'T -> Async<unit>) (linkedActors: #seq<Actor>) =
          let rec body (actor: Actor<'T>) = async { 
                  let! msg = actor.Receive()
                  do! reactF msg
                  return! body actor
              }
          bindLinked body linkedActors
  
      /// <summary>
      ///     Publish given actor implementation to provided protocol implementation factories.
      /// </summary>
      /// <param name="protocolFactories">Protocol factories.</param>
      /// <param name="actor">Target actor.</param>
      let inline publish (protocolFactories: #seq<'U> when 'U :> IProtocolFactory) (actor: Actor<'T>): Actor<'T> = 
          actor.Publish(protocolFactories)
  
      /// <summary>
      ///     Creates a copy of the actor instance with a new name.
      /// </summary>
      /// <param name="newName">New actor name.</param>
      /// <param name="actor">Target actor.</param>
      let inline rename (newName: string) (actor: Actor<'T>): Actor<'T> = actor.Rename(newName)
  
      /// <summary>
      ///     Starts the given actor instance.
      /// </summary>
      /// <param name="actor">Actor to be started.</param>
      let inline start (actor: Actor<'T>): Actor<'T> = actor.Start(); actor
  
      /// <summary>
      ///     Creates a new actor that intercepts messages
      ///     before forwarding them to the target actor.
      /// </summary>
      /// <param name="interceptF">Interception behavior.</param>
      /// <param name="actor">Target actor.</param>
      let intercept (interceptF: 'T -> Async<unit>) (actor: Actor<'T>): Actor<'T> =
          spawnLinked (fun msg -> async {                
              do! interceptF msg
  
              return! !actor <-!- msg
          }) [actor]
  
      /// <summary>
      ///     Creates a new actor that only forwards messages
      ///     which satisfy given predicate.
      /// </summary>
      /// <param name="predicate">Predicate function.</param>
      /// <param name="actor">Target actor.</param>
      let filter (predicate: 'T -> bool) (actor: Actor<'T>): Actor<'T> =
          spawnLinked (fun msg -> async { if predicate msg then return! !actor <-!- msg }) [actor]
  
      /// <summary>
      ///     Creates a new actor that broadcasts message received to
      ///     all target actors.
      /// </summary>
      /// <param name="actors">Target actors.</param>
      let broadcast (actors: #seq<Actor<'T>>): Actor<'T> =
          let rec broadcastBehavior (self: Actor<'T>) =
              async {
                  let! msg = self.Receive()
  
                  let send actor = async {
                      try
                          return! !actor <-!- msg
                      with e -> self.LogWarning e
                  }
  
                  do! actors |> Seq.map send |> Async.Parallel |> Async.Ignore
  
                  return! broadcastBehavior self
              }
          actors |> Seq.map (fun a -> a :> Actor) |> bindLinked broadcastBehavior
  
      /// <summary>
      ///     Creates a new actor that passes incoming messages through a choice predicate;
      ///     successful inputs are passed to the first actor, whereas failed will be passed to
      ///     the failed actor.
      /// </summary>
      /// <param name="choiceF">Choice predicate.</param>
      /// <param name="actorOnSuccess">Actor to forward message on true.</param>
      /// <param name="actorOnFail">Actor to forward message on false.</param>
      let split (choiceF: 'T -> bool) (actorOnSuccess: Actor<'T>, actorOnFail: Actor<'T>): Actor<'T> =
          spawnLinked (fun msg -> async {
              if choiceF msg then return! !actorOnSuccess <-!- msg
              else return! !actorOnFail <-!- msg
          }) [actorOnSuccess; actorOnFail]
  
      /// <summary>
      ///     Balance message passing across a collection of actors using a selection function.
      /// </summary>
      /// <param name="select">Selection function.</param>
      /// <param name="actors">Target actors.</param>
      let balance (select: seq<ActorRef<'T>> -> ActorRef<'T>) (actors: #seq<Actor<'T>>): Actor<'T> =
          let actors = Seq.toArray actors
          let balancer msg = async {
              let selectedRef = actors |> Seq.map (!) |> select
              return! selectedRef <-!- msg
          }
          spawnLinked balancer (actors |> Array.map (fun a -> a :> Actor))
  
      /// <summary>
      ///     Creates an actor that maps messages to target actor.
      /// </summary>
      /// <param name="mapF">Mapping function.</param>
      /// <param name="actor">Target actor.</param>
      let map (mapF: 'U -> 'T) (actor: Actor<'T>) : Actor<'U> =
          spawnLinked (fun msg -> async {
              return! !actor <-!- (mapF msg) 
          }) [actor]
  
      /// <summary>
      ///     Creates an actor that forwards to target actors according to an indexing function.
      /// </summary>
      /// <param name="partitionF">Indexing function.</param>
      /// <param name="actors">Target actors.</param>
      let partition (partitionF: 'T -> int) (actors: #seq<Actor<'T>>): Actor<'T> =
          let actors = Seq.toArray actors
          spawnLinked (fun msg -> async {
              let selected = partitionF msg
              return! !actors.[selected] <-!- msg
          }) (actors |> Array.map (fun a -> a :> Actor))
  
  
  //    let scatter (choiceF: 'T -> (IReplyChannel<'R> * (IReplyChannel<'R> -> 'T)) option) 
  //        (gatherF: seq<Reply<'R>> -> Reply<'R>) 
  //        (actors: #seq<Actor<'T>>): Actor<'T> =
  //
  //        spawnLinked (fun msg -> async {
  //            match choiceF msg with
  //            | Some(replyChannel, msgBuilder) -> 
  //                let! results =
  //                    [ for actor in actors -> async {
  //                            try
  //                                let! result = !actor <!- msgBuilder
  //                                return Value result
  //                            with e ->
  //                                return Exn e
  //                        }
  //                    ] |> Async.Parallel
  //                return! results |> Array.toSeq |> gatherF |> replyChannel.AsyncReply
  //            | None -> ()
  //        }) (actors |> Seq.map (fun a -> a :> Actor))
  
      /// <summary>
      ///     Gets reference to given actor.
      /// </summary>
      /// <param name="actor">Input actor.</param>
      let inline ref (actor: Actor<'T>): ActorRef<'T> = actor.Ref
  
      /// <summary>
      ///     Creates a local actor instance that forwards messages to target ActorRef.
      /// </summary>
      /// <param name="actorRef">Target ActorRef.</param>
      let wrapRef (actorRef: ActorRef<'T>): Actor<'T> =
          let rec body (self: Actor<'T>) = async {
              let! msg = self.Receive()
              do! actorRef <-!- msg
  
              return! body self
          }
  