recursivelyImportExternalValue :: L2.L2Model -> L2.Identifier -> L2.L2ValueID -> ModelTranslation L2.L2ValueID
recursivelyImportExternalValue =
  cacheWrapExternalImport mtsForeignToLocalValues (\x m -> m{mtsForeignToLocalValues=x}) $
    \foreignMod foreignURL foreignValueID -> do
      let foreignValueContents = (fromJust . M.lookup foreignValueID . L2.l2AllValues $ foreignMod)
      newValueID <- L2.l2NextValue <$> getL2Model
      localValueContents <- L2.L2ValueContents (L2.l2ValueSS foreignValueContents) <$>
                              maybe (return Nothing)
                                (\fvc -> Just <$>
                                         recursivelyImportExternalDomainExpression foreignMod foreignURL fvc)
                                (L2.l2ValueType foreignValueContents)
      modifyL2Model $ \mod -> mod {
        L2.l2NextValue = (\(L2.L2ValueID i) -> L2.L2ValueID (i + 1)) newValueID,
        L2.l2AllValues = M.insert newValueID localValueContents
                              (L2.l2AllValues mod)
        }
      return newValueID
recursivelyImportExternalValue :: L2.L2Model -> L2.Identifier -> L2.L2ValueID -> ModelTranslation L2.L2ValueID
recursivelyImportExternalValue =
  cacheWrapExternalImport mtsForeignToLocalValues (\x m -> m{mtsForeignToLocalValues=x}) $
    \foreignMod foreignURL foreignValueID -> do
      let foreignValueContents = (fromJust . M.lookup foreignValueID . L2.l2AllValues $ foreignMod)
      newValueID <- L2.l2NextValue <$> getL2Model
      localValueContents <- L2.L2ValueContents (L2.l2ValueSS foreignValueContents) <$>
                              maybe (return Nothing)
                                (\fvc -> Just <$>
                                         recursivelyImportExternalDomainExpression foreignMod foreignURL fvc)
                                (L2.l2ValueType foreignValueContents)
      modifyL2Model $ \mod -> mod {
        L2.l2NextValue = (\(L2.L2ValueID i) -> L2.L2ValueID (i + 1)) newValueID,
        L2.l2AllValues = M.insert newValueID localValueContents
                              (L2.l2AllValues mod)
        }
      return newValueID
recursivelyImportExternalValue =
  cacheWrapExternalImport mtsForeignToLocalValues (\x m -> m{mtsForeignToLocalValues=x}) $
    \foreignMod foreignURL foreignValueID -> do
      let foreignValueContents = (fromJust . M.lookup foreignValueID . L2.l2AllValues $ foreignMod)
      newValueID <- L2.l2NextValue <$> getL2Model
      localValueContents <- L2.L2ValueContents (L2.l2ValueSS foreignValueContents) <$>
                              maybe (return Nothing)
                                (\fvc -> Just <$>
                                         recursivelyImportExternalDomainExpression foreignMod foreignURL fvc)
                                (L2.l2ValueType foreignValueContents)
      modifyL2Model $ \mod -> mod {
        L2.l2NextValue = (\(L2.L2ValueID i) -> L2.L2ValueID (i + 1)) newValueID,
        L2.l2AllValues = M.insert newValueID localValueContents
                              (L2.l2AllValues mod)
        }
      return newValueID