translateL1ToL2 :: String -> L1.L1NamespaceContents -> M.Map BS.ByteString L2.L2Model -> ErrorT String IO L2.L2Model
translateL1ToL2 mpath l1ns impmap =
  flip runReaderT (handleL1SimpleSyntacticSugar (BSC.pack mpath) l1ns, mpath, impmap) $
    flip evalStateT ((def :: ModelTranslationState) { mtsL2ToL1Map = M.singleton nsMain l1ns} ) $ do
      -- Create a skeleton model, where all symbols except those that are
      -- imported exist, but do not yet have their proper definitions set up
      -- yet.
      (l1ns, _, _) <- ask
      buildSkeletonModel (L1.SrcSpan mpath 0 0 0 0) l1ns nsMain
      -- Load all external imports into the model.
      processExternalImports nsMain
      -- Resolve all internal imports in the model.
      processInternalImports nsMain
      -- Fill out the model skeleton with the actual functions.
      recursivelyTranslateModel nsMain
      -- Repair references to temporary IDs for aliases...
      fixAliasReferences nsMain
      getL2Model
translateL1ToL2 :: String -> L1.L1NamespaceContents -> M.Map BS.ByteString L2.L2Model -> ErrorT String IO L2.L2Model
translateL1ToL2 mpath l1ns impmap =
  flip runReaderT (handleL1SimpleSyntacticSugar (BSC.pack mpath) l1ns, mpath, impmap) $
    flip evalStateT ((def :: ModelTranslationState) { mtsL2ToL1Map = M.singleton nsMain l1ns} ) $ do
      -- Create a skeleton model, where all symbols except those that are
      -- imported exist, but do not yet have their proper definitions set up
      -- yet.
      (l1ns, _, _) <- ask
      buildSkeletonModel (L1.SrcSpan mpath 0 0 0 0) l1ns nsMain
      -- Load all external imports into the model.
      processExternalImports nsMain
      -- Resolve all internal imports in the model.
      processInternalImports nsMain
      -- Fill out the model skeleton with the actual functions.
      recursivelyTranslateModel nsMain
      -- Repair references to temporary IDs for aliases...
      fixAliasReferences nsMain
      getL2Model
translateL1ToL2 mpath l1ns impmap =
  flip runReaderT (handleL1SimpleSyntacticSugar (BSC.pack mpath) l1ns, mpath, impmap) $
    flip evalStateT ((def :: ModelTranslationState) { mtsL2ToL1Map = M.singleton nsMain l1ns} ) $ do
      -- Create a skeleton model, where all symbols except those that are
      -- imported exist, but do not yet have their proper definitions set up
      -- yet.
      (l1ns, _, _) <- ask
      buildSkeletonModel (L1.SrcSpan mpath 0 0 0 0) l1ns nsMain
      -- Load all external imports into the model.
      processExternalImports nsMain
      -- Resolve all internal imports in the model.
      processInternalImports nsMain
      -- Fill out the model skeleton with the actual functions.
      recursivelyTranslateModel nsMain
      -- Repair references to temporary IDs for aliases...
      fixAliasReferences nsMain
      getL2Model