addStateAndTransitionsOfR :: (Ord sym, Ord sta) => Fa sym sta -> Set sym -> Set sta -> State (InnerState sym sta) ()
addStateAndTransitionsOfR fa symbols r = state $ \(!oldFront, !oldStates, !oldTransitions) ->
  let
    rWithSymbol = Set.map (\symbol -> (post fa r symbol, symbol)) symbols
    r' = Set.map fst rWithSymbol
    newTransitions = oldTransitions `Set.union` Set.map (\(newR, symbol) -> Transition symbol r newR) rWithSymbol
    newFront = oldFront `Set.union` Set.filter (`Set.notMember` oldStates) r'
  in
    ((), (newFront, oldStates, newTransitions))
addStateAndTransitionsOfR :: (Ord sym, Ord sta) => Fa sym sta -> Set sym -> Set sta -> State (InnerState sym sta) ()
addStateAndTransitionsOfR fa symbols r = state $ \(!oldFront, !oldStates, !oldTransitions) ->
  let
    rWithSymbol = Set.map (\symbol -> (post fa r symbol, symbol)) symbols
    r' = Set.map fst rWithSymbol
    newTransitions = oldTransitions `Set.union` Set.map (\(newR, symbol) -> Transition symbol r newR) rWithSymbol
    newFront = oldFront `Set.union` Set.filter (`Set.notMember` oldStates) r'
  in
    ((), (newFront, oldStates, newTransitions))
addStateAndTransitionsOfR fa symbols r = state $ \(!oldFront, !oldStates, !oldTransitions) ->
  let
    rWithSymbol = Set.map (\symbol -> (post fa r symbol, symbol)) symbols
    r' = Set.map fst rWithSymbol
    newTransitions = oldTransitions `Set.union` Set.map (\(newR, symbol) -> Transition symbol r newR) rWithSymbol
    newFront = oldFront `Set.union` Set.filter (`Set.notMember` oldStates) r'
  in
    ((), (newFront, oldStates, newTransitions))