-- Replace the secondary (r:ns)
applyMove nl inst (ReplaceSecondary new_sdx) =
  let old_pdx = Instance.pNode inst
      old_sdx = Instance.sNode inst
      old_s = Container.find old_sdx nl
      tgt_n = Container.find new_sdx nl
      int_s = Node.removeSec old_s inst
      force_s = Node.offline old_s
      new_inst = Instance.setSec inst new_sdx
      new_nl = Node.addSecEx force_s tgt_n inst old_pdx >>=
               \new_s -> return (Container.addTwo new_sdx
                                 new_s old_sdx int_s nl,
                                 new_inst, old_pdx, new_sdx)
  in new_nl
applyMove nl inst (ReplaceSecondary new_sdx) =
  let old_pdx = Instance.pNode inst
      old_sdx = Instance.sNode inst
      old_s = Container.find old_sdx nl
      tgt_n = Container.find new_sdx nl
      int_s = Node.removeSec old_s inst
      force_s = Node.offline old_s
      new_inst = Instance.setSec inst new_sdx
      new_nl = Node.addSecEx force_s tgt_n inst old_pdx >>=
               \new_s -> return (Container.addTwo new_sdx
                                 new_s old_sdx int_s nl,
                                 new_inst, old_pdx, new_sdx)
  in new_nl
applyMove nl inst (ReplaceSecondary new_sdx) =
  let old_pdx = Instance.pNode inst
      old_sdx = Instance.sNode inst
      old_s = Container.find old_sdx nl
      tgt_n = Container.find new_sdx nl
      int_s = Node.removeSec old_s inst
      force_s = Node.offline old_s
      new_inst = Instance.setSec inst new_sdx
      new_nl = Node.addSecEx force_s tgt_n inst old_pdx >>=
               \new_s -> return (Container.addTwo new_sdx
                                 new_s old_sdx int_s nl,
                                 new_inst, old_pdx, new_sdx)
  in new_nl