recursivelyImportExternalBaseUnit :: L2.L2Model -> L2.Identifier -> L2.L2BaseUnitsID -> ModelTranslation L2.L2BaseUnitsID
recursivelyImportExternalBaseUnit = cacheWrapExternalImport mtsForeignToLocalBaseUnits (\x m -> m{mtsForeignToLocalBaseUnits=x}) $
                                    \foreignMod foreignURL bu -> do
  newBUID <- L2.l2NextBaseUnits <$> getL2Model
  modifyL2Model $ \mod -> mod {
    L2.l2NextBaseUnits = (\(L2.L2BaseUnitsID i) -> L2.L2BaseUnitsID (i + 1)) newBUID,
    -- Note that L2BaseUnitContents only contains a SrcSpan so needs no translation...
    L2.l2AllBaseUnits = M.insert newBUID (fromJust . M.lookup bu . L2.l2AllBaseUnits $ foreignMod)
                                 (L2.l2AllBaseUnits mod)
    }
  return newBUID
recursivelyImportExternalBaseUnit :: L2.L2Model -> L2.Identifier -> L2.L2BaseUnitsID -> ModelTranslation L2.L2BaseUnitsID
recursivelyImportExternalBaseUnit = cacheWrapExternalImport mtsForeignToLocalBaseUnits (\x m -> m{mtsForeignToLocalBaseUnits=x}) $
                                    \foreignMod foreignURL bu -> do
  newBUID <- L2.l2NextBaseUnits <$> getL2Model
  modifyL2Model $ \mod -> mod {
    L2.l2NextBaseUnits = (\(L2.L2BaseUnitsID i) -> L2.L2BaseUnitsID (i + 1)) newBUID,
    -- Note that L2BaseUnitContents only contains a SrcSpan so needs no translation...
    L2.l2AllBaseUnits = M.insert newBUID (fromJust . M.lookup bu . L2.l2AllBaseUnits $ foreignMod)
                                 (L2.l2AllBaseUnits mod)
    }
  return newBUID
recursivelyImportExternalBaseUnit = cacheWrapExternalImport mtsForeignToLocalBaseUnits (\x m -> m{mtsForeignToLocalBaseUnits=x}) $
                                    \foreignMod foreignURL bu -> do
  newBUID <- L2.l2NextBaseUnits <$> getL2Model
  modifyL2Model $ \mod -> mod {
    L2.l2NextBaseUnits = (\(L2.L2BaseUnitsID i) -> L2.L2BaseUnitsID (i + 1)) newBUID,
    -- Note that L2BaseUnitContents only contains a SrcSpan so needs no translation...
    L2.l2AllBaseUnits = M.insert newBUID (fromJust . M.lookup bu . L2.l2AllBaseUnits $ foreignMod)
                                 (L2.l2AllBaseUnits mod)
    }
  return newBUID