findScopedSymbolByRAPath :: L1.SrcSpan -> L2.L2NamespaceID -> L1.L1RelOrAbsPath ->
                            (L2.L2NamespaceContents -> L1.L1Identifier -> Maybe a) -> ModelTranslation a
findScopedSymbolByRAPath ss startNS ra tryGet = do
  (nsra@(L1.L1RelOrAbsPath _ isabs rp), symName) <- maybe (fail $ "Inappropriate use of an empty path, at " ++ show ss)
                             return $ trySplitRAPathOnLast ra
  -- Recursively find the namespace...
  nsid <- findNamespaceByRAPath ss startNS nsra
  let foldStrategy =
        if (not isabs && null (L1.l1RelPathIDs rp))
           then flip (flip foldOverNSScopesM Nothing) nsid
           else (\x -> x Nothing nsid)
  r <- foldStrategy $ \s nsid' -> (mplus s) <$> do
    nsc <- (fromJust . M.lookup nsid' . L2.l2AllNamespaces) <$> getL2Model
    return $ tryGet nsc symName
  maybe (fail $ "Symbol " ++ (BSC.unpack . L1.l1IdBS $ symName) ++
                " not found in namespace at " ++ (show . L1.l1IdSS $ symName)) return r
findScopedSymbolByRAPath :: L1.SrcSpan -> L2.L2NamespaceID -> L1.L1RelOrAbsPath ->
                            (L2.L2NamespaceContents -> L1.L1Identifier -> Maybe a) -> ModelTranslation a
findScopedSymbolByRAPath ss startNS ra tryGet = do
  (nsra@(L1.L1RelOrAbsPath _ isabs rp), symName) <- maybe (fail $ "Inappropriate use of an empty path, at " ++ show ss)
                             return $ trySplitRAPathOnLast ra
  -- Recursively find the namespace...
  nsid <- findNamespaceByRAPath ss startNS nsra
  let foldStrategy =
        if (not isabs && null (L1.l1RelPathIDs rp))
           then flip (flip foldOverNSScopesM Nothing) nsid
           else (\x -> x Nothing nsid)
  r <- foldStrategy $ \s nsid' -> (mplus s) <$> do
    nsc <- (fromJust . M.lookup nsid' . L2.l2AllNamespaces) <$> getL2Model
    return $ tryGet nsc symName
  maybe (fail $ "Symbol " ++ (BSC.unpack . L1.l1IdBS $ symName) ++
                " not found in namespace at " ++ (show . L1.l1IdSS $ symName)) return r
findScopedSymbolByRAPath ss startNS ra tryGet = do
  (nsra@(L1.L1RelOrAbsPath _ isabs rp), symName) <- maybe (fail $ "Inappropriate use of an empty path, at " ++ show ss)
                             return $ trySplitRAPathOnLast ra
  -- Recursively find the namespace...
  nsid <- findNamespaceByRAPath ss startNS nsra
  let foldStrategy =
        if (not isabs && null (L1.l1RelPathIDs rp))
           then flip (flip foldOverNSScopesM Nothing) nsid
           else (\x -> x Nothing nsid)
  r <- foldStrategy $ \s nsid' -> (mplus s) <$> do
    nsc <- (fromJust . M.lookup nsid' . L2.l2AllNamespaces) <$> getL2Model
    return $ tryGet nsc symName
  maybe (fail $ "Symbol " ++ (BSC.unpack . L1.l1IdBS $ symName) ++
                " not found in namespace at " ++ (show . L1.l1IdSS $ symName)) return r