recursivelyImportExternalDomainFunction :: L2.L2Model -> L2.Identifier -> L2.L2DomainFunctionID -> ModelTranslation L2.L2DomainFunctionID
recursivelyImportExternalDomainFunction =
  cacheWrapExternalImport mtsForeignToLocalDomainFunction (\x m -> m{mtsForeignToLocalDomainFunction=x}) $
   \foreignMod foreignURL foreignDF -> do
     newDFID <- L2.l2NextDomainFunctionID <$> getL2Model
     -- No need for any translation...
     let Just localDFContents = M.lookup foreignDF (L2.l2AllDomainFunctions foreignMod)
     modifyL2Model $ \mod -> mod {
       L2.l2NextDomainFunctionID = (\(L2.L2DomainFunctionID i) -> L2.L2DomainFunctionID (i + 1)) newDFID,
       L2.l2AllDomainFunctions = M.insert newDFID localDFContents
                                   (L2.l2AllDomainFunctions mod)
       }
     return newDFID

-- | Process internal imports until either all imports are resolved, or an
--   error such as a cycle or missing identifier is found.
recursivelyImportExternalDomainFunction :: L2.L2Model -> L2.Identifier -> L2.L2DomainFunctionID -> ModelTranslation L2.L2DomainFunctionID
recursivelyImportExternalDomainFunction =
  cacheWrapExternalImport mtsForeignToLocalDomainFunction (\x m -> m{mtsForeignToLocalDomainFunction=x}) $
   \foreignMod foreignURL foreignDF -> do
     newDFID <- L2.l2NextDomainFunctionID <$> getL2Model
     -- No need for any translation...
     let Just localDFContents = M.lookup foreignDF (L2.l2AllDomainFunctions foreignMod)
     modifyL2Model $ \mod -> mod {
       L2.l2NextDomainFunctionID = (\(L2.L2DomainFunctionID i) -> L2.L2DomainFunctionID (i + 1)) newDFID,
       L2.l2AllDomainFunctions = M.insert newDFID localDFContents
                                   (L2.l2AllDomainFunctions mod)
       }
     return newDFID

-- | Process internal imports until either all imports are resolved, or an
--   error such as a cycle or missing identifier is found.
recursivelyImportExternalDomainFunction =
  cacheWrapExternalImport mtsForeignToLocalDomainFunction (\x m -> m{mtsForeignToLocalDomainFunction=x}) $
   \foreignMod foreignURL foreignDF -> do
     newDFID <- L2.l2NextDomainFunctionID <$> getL2Model
     -- No need for any translation...
     let Just localDFContents = M.lookup foreignDF (L2.l2AllDomainFunctions foreignMod)
     modifyL2Model $ \mod -> mod {
       L2.l2NextDomainFunctionID = (\(L2.L2DomainFunctionID i) -> L2.L2DomainFunctionID (i + 1)) newDFID,
       L2.l2AllDomainFunctions = M.insert newDFID localDFContents
                                   (L2.l2AllDomainFunctions mod)
       }
     return newDFID

-- | Process internal imports until either all imports are resolved, or an
--   error such as a cycle or missing identifier is found.