anchor.diff:                          else
                               // Pass a continuation which'll be called once the previous element
                               // (at index = (argIdx - 1)) is mapped and stored in the results array.
  -                            buildFirstArgCont (idx - 1) <| fun (prevElementResult, state : 'State) ->
  +                            buildCont (idx - 1) <| fun (prevElementResult, state : 'State) ->
                                   // Save the _previous_ element's accumulator into the array
                                   results.[idx - 1] <- prevElementResult
   
  
positive.code: 
                      /// Iterates backwards over the array elements, creating a chain of continuations
                      /// which'll process them in order (from left-to-right) when executed.
                      let rec buildFirstArgCont idx cont =
                          // The first element needs to be handled specially.
                          if idx = 0 then
                              // Pass the initial state to the mapping function when processing the first element.
  
negative.code: 
  //
  [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
  module ProtectedState =
      /// The standard F# Array module, lifted into the ProtectedState monad.
      [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
      module Array =
          /// A specialization of Array.iter which threads an accumulator through the computation
          /// and which also short-circuits the computation if the mapping function returns an
          /// error when any element is applied to it.
          [<CompiledName("Iterate")>]
          let iter (action : 'T -> 'State -> Choice<unit * 'State, 'Error>)
                  (array : 'T[]) (state : 'State) : Choice<unit * 'State, 'Error> =
              // Preconditions
              checkNonNull "array" array
  
              let action = FSharpFunc<_,_,_>.Adapt action
              let len = array.Length
  
              let mutable index = 0
              let mutable state = state
              let mutable error = None
  
              while index < len && Option.isNone error do
                  match action.Invoke (array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 ((), state') ->
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 ((), state)
  
          /// A specialization of Array.iteri which threads an accumulator through the computation
          /// and which also short-circuits the computation if the mapping function returns an
          /// error when any element is applied to it.
          [<CompiledName("IterateIndexed")>]
          let iteri (action : int -> 'T -> 'State -> Choice<unit * 'State, 'Error>)
                  (array : 'T[]) (state : 'State) : Choice<unit * 'State, 'Error> =
              // Preconditions
              checkNonNull "array" array
  
              let action = FSharpFunc<_,_,_,_>.Adapt action
              let len = array.Length
  
              let mutable index = 0
              let mutable state = state
              let mutable error = None
  
              while index < len && Option.isNone error do
                  match action.Invoke (index, array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 ((), state') ->
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 ((), state)
  
          /// A specialization of Array.map which threads an accumulator through the computation
          /// and which also short-circuits the computation if the mapping function returns an
          /// error when any element is applied to it.
          [<CompiledName("Map")>]
          let map (mapping : 'T -> 'State -> Choice<'U * 'State, 'Error>)
                  (array : 'T[]) (state : 'State) : Choice<'U[] * 'State, 'Error> =
              // Preconditions
              checkNonNull "array" array
  
              let mapping = FSharpFunc<_,_,_>.Adapt mapping
              let len = array.Length
              let results = Array.zeroCreate len
  
              let mutable index = 0
              let mutable state = state
              let mutable error = None
  
              while index < len && Option.isNone error do
                  match mapping.Invoke (array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 (result, state') ->
                      results.[index] <- result
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 (results, state)
  
          /// A specialization of Array.mapi which threads an accumulator through the computation
          /// and which also short-circuits the computation if the mapping function returns an
          /// error when any element is applied to it.
          [<CompiledName("MapIndexed")>]
          let mapi (mapping : int -> 'T -> 'State -> Choice<'U * 'State, 'Error>)
                  (array : 'T[]) (state : 'State) : Choice<'U[] * 'State, 'Error> =
              // Preconditions
              checkNonNull "array" array
  
              let mapping = FSharpFunc<_,_,_,_>.Adapt mapping
              let len = array.Length
              let results = Array.zeroCreate len
  
              let mutable index = 0
              let mutable state = state
              let mutable error = None
  
              while index < len && Option.isNone error do
                  match mapping.Invoke (index, array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 (result, state') ->
                      results.[index] <- result
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 (results, state)
  
  
      /// The standard F# List module, lifted into the ProtectedState monad.
      [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
      module List =
          /// A specialization of List.map which threads an accumulator through the computation
          /// and which also short-circuits the computation if the mapping function returns an
          /// error when any element is applied to it.
          [<CompiledName("Map")>]
          let map (mapping : 'T -> 'State -> Choice<'U * 'State, 'Error>)
                  (list : 'T list) (state : 'State) : Choice<'U list * 'State, 'Error> =
              // Preconditions
              checkNonNull "list" list
  
              let mapping = FSharpFunc<_,_,_>.Adapt mapping
              
              let rec mapRec (results, state, lst) =
                  match lst with
                  | [] ->
                      let results = List.rev results
                      Choice1Of2 (results, state)
                  | hd :: tl ->
                      // Apply the function to the head of the list.
                      // If the result is an error, return it;
                      // otherwise, continue processing recursively.
                      match mapping.Invoke (hd, state) with
                      | Choice2Of2 error ->
                          Choice2Of2 error
                      | Choice1Of2 (result, state) ->
                          mapRec (result :: results, state, tl)
  
              // Call the recursive implementation function.
              mapRec ([], state, list)
  
  
      /// The ExtCore.Collections.ArraySegment module, lifted into the ProtectedState monad.
      [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
      module ArraySegment =
          /// A specialization of ArraySegment.iter which threads an accumulator through the
          /// computation and which also short-circuits the computation if the mapping function
          /// returns an error when any element is applied to it.
          [<CompiledName("Iterate")>]
          let iter (action : 'T -> 'State -> Choice<unit * 'State, 'Error>)
                  (segment : System.ArraySegment<'T>) (state : 'State) : Choice<unit * 'State, 'Error> =
              let action = FSharpFunc<_,_,_>.Adapt action
  
              let array = segment.Array
              let endExclusive = segment.Offset + segment.Count
  
              let mutable index = segment.Offset
              let mutable state = state
              let mutable error = None
  
              while index < endExclusive && Option.isNone error do
                  match action.Invoke (array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 ((), state') ->
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 ((), state)
  
          /// A specialization of ArraySegment.iteri which threads an accumulator through the
          /// computation and which also short-circuits the computation if the mapping function
          /// returns an error when any element is applied to it.
          [<CompiledName("IterateIndexed")>]
          let iteri (action : int -> 'T -> 'State -> Choice<unit * 'State, 'Error>)
                  (segment : System.ArraySegment<'T>) (state : 'State) : Choice<unit * 'State, 'Error> =
              let action = FSharpFunc<_,_,_,_>.Adapt action
  
              let array = segment.Array
              let endExclusive = segment.Offset + segment.Count
  
              let mutable index = segment.Offset
              let mutable state = state
              let mutable error = None
  
              while index < endExclusive && Option.isNone error do
                  match action.Invoke (index, array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 ((), state') ->
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 ((), state)
  
          /// A specialization of ArraySegment.map which threads an accumulator through the
          /// computation and which also short-circuits the computation if the mapping function
          /// returns an error when any element is applied to it.
          [<CompiledName("Map")>]
          let map (mapping : 'T -> 'State -> Choice<'U * 'State, 'Error>)
                  (segment : System.ArraySegment<'T>) (state : 'State) : Choice<'U[] * 'State, 'Error> =
              let mapping = FSharpFunc<_,_,_>.Adapt mapping
  
              let array = segment.Array
              let endExclusive = segment.Offset + segment.Count
              /// Holds the mapped results.
              let results = Array.zeroCreate segment.Count
  
              let mutable index = segment.Offset
              let mutable state = state
              let mutable error = None
  
              while index < endExclusive && Option.isNone error do
                  match mapping.Invoke (array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 (result, state') ->
                      results.[index] <- result
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 (results, state)
  
          /// A specialization of ArraySegment.mapi which threads an accumulator through the
          /// computation and which also short-circuits the computation if the mapping function
          /// returns an error when any element is applied to it.
          [<CompiledName("MapIndexed")>]
          let mapi (mapping : int -> 'T -> 'State -> Choice<'U * 'State, 'Error>)
                  (segment : System.ArraySegment<'T>) (state : 'State) : Choice<'U[] * 'State, 'Error> =
              let mapping = FSharpFunc<_,_,_,_>.Adapt mapping
  
              let array = segment.Array
              let endExclusive = segment.Offset + segment.Count
              /// Holds the mapped results.
              let results = Array.zeroCreate segment.Count
  
              let mutable index = segment.Offset
              let mutable state = state
              let mutable error = None
  
              while index < endExclusive && Option.isNone error do
                  match mapping.Invoke (index, array.[index], state) with
                  | Choice2Of2 err ->
                      error <- Some err
                  | Choice1Of2 (result, state') ->
                      results.[index] <- result
                      state <- state'
                      index <- index + 1
              
              // If the error was set, return it.
              // Otherwise return the result and updated state.
              match error with
              | Some error ->
                  Choice2Of2 error
              | None ->
                  Choice1Of2 (results, state)
  
  
  //
  [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
  module ReaderProtectedState =
      /// The standard F# Array module, lifted into the ReaderProtectedState monad.
      [<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
  