checkArgs :: [TypedVariable b NodeMeta] -> FunctionOrMethod -> ErrorOr ()
checkArgs args functionOrMethod = evalStateT (mapM_ checkArg args) M.empty
  where checkArg :: TypedVariable b NodeMeta -> StateT (M.Map Name SourcePos) (ExceptT Error Identity) ()
        checkArg var = do
          let name = varName var
          let pos = typedVarPos var
          case B.stringToBuiltinVar name of
            Just B.Result -> lift $ resultArg pos
            _             -> return ()
          previousPos <- gets $ M.lookup name
          case previousPos of
            Just pos' -> lift $ redeclaredArgument name functionOrMethod pos' pos
            Nothing   -> return ()
          modify $ M.insert name pos
          return ()
checkArgs :: [TypedVariable b NodeMeta] -> FunctionOrMethod -> ErrorOr ()
checkArgs args functionOrMethod = evalStateT (mapM_ checkArg args) M.empty
  where checkArg :: TypedVariable b NodeMeta -> StateT (M.Map Name SourcePos) (ExceptT Error Identity) ()
        checkArg var = do
          let name = varName var
          let pos = typedVarPos var
          case B.stringToBuiltinVar name of
            Just B.Result -> lift $ resultArg pos
            _             -> return ()
          previousPos <- gets $ M.lookup name
          case previousPos of
            Just pos' -> lift $ redeclaredArgument name functionOrMethod pos' pos
            Nothing   -> return ()
          modify $ M.insert name pos
          return ()
checkArgs args functionOrMethod = evalStateT (mapM_ checkArg args) M.empty
  where checkArg :: TypedVariable b NodeMeta -> StateT (M.Map Name SourcePos) (ExceptT Error Identity) ()
        checkArg var = do
          let name = varName var
          let pos = typedVarPos var
          case B.stringToBuiltinVar name of
            Just B.Result -> lift $ resultArg pos
            _             -> return ()
          previousPos <- gets $ M.lookup name
          case previousPos of
            Just pos' -> lift $ redeclaredArgument name functionOrMethod pos' pos
            Nothing   -> return ()
          modify $ M.insert name pos
          return ()