recursivelyImportExternalDomainExpression :: L2.L2Model -> L2.Identifier -> L2.L2DomainExpression -> ModelTranslation L2.L2DomainExpression
recursivelyImportExternalDomainExpression foreignMod foreignURL targetEx =
  case targetEx of
    L2.L2DomainExpressionProduct ss l ->
      L2.L2DomainExpressionProduct ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionDisjointUnion ss l ->
      L2.L2DomainExpressionDisjointUnion ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionFieldSignature ss dd dcd ->
      L2.L2DomainExpressionFieldSignature ss
        <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dd
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dcd
    L2.L2DomainExpressionReal ss u ->
      L2.L2DomainExpressionReal ss
        <$> recursivelyImportExternalUnitExpression foreignMod foreignURL u
    L2.L2DomainExpressionApply ss domArgs unitArgs val ->
      L2.L2DomainExpressionApply ss
        <$> mapM (\(sdid, domExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalDomainExpression foreignMod foreignURL domExpr)
                 domArgs
        <*> mapM (\(sdid, unitExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalUnitExpression foreignMod foreignURL unitExpr)
                 unitArgs
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL val
    L2.L2DomainFunctionEvaluate ss dfid args ->
      L2.L2DomainFunctionEvaluate ss
        <$> recursivelyImportExternalDomainFunction foreignMod foreignURL dfid
        <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) args
    L2.L2DomainVariableRef ss sdid ->
      L2.L2DomainVariableRef ss <$> (recursivelyImportExternalScopedDomain foreignMod foreignURL sdid)
    L2.L2DomainExpressionLambda ss scopedDoms scopedUnits uConstraints dEqs dRels dex ->
      L2.L2DomainExpressionLambda ss
        <$> mapM (\(d, k) ->
                   (,)
                     <$> recursivelyImportExternalScopedDomain foreignMod foreignURL d
                     <*> pure k) scopedDoms
        <*> mapM (recursivelyImportExternalScopedUnit foreignMod foreignURL) scopedUnits
        <*> mapM (\(uex1, uex2) -> (,)
                    <$> recursivelyImportExternalUnitExpression foreignMod foreignURL uex1
                    <*> recursivelyImportExternalUnitExpression foreignMod foreignURL uex2) uConstraints
        <*> mapM (\(dex1, dex2) -> (,)
                    <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dex1
                    <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex2) dEqs
        <*> mapM (\(cls, dexs) -> (,)
                      <$> recursivelyImportExternalClassExpression foreignMod foreignURL cls
                      <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) dexs
                 ) dRels
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex
recursivelyImportExternalDomainExpression :: L2.L2Model -> L2.Identifier -> L2.L2DomainExpression -> ModelTranslation L2.L2DomainExpression
recursivelyImportExternalDomainExpression foreignMod foreignURL targetEx =
  case targetEx of
    L2.L2DomainExpressionProduct ss l ->
      L2.L2DomainExpressionProduct ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionDisjointUnion ss l ->
      L2.L2DomainExpressionDisjointUnion ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionFieldSignature ss dd dcd ->
      L2.L2DomainExpressionFieldSignature ss
        <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dd
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dcd
    L2.L2DomainExpressionReal ss u ->
      L2.L2DomainExpressionReal ss
        <$> recursivelyImportExternalUnitExpression foreignMod foreignURL u
    L2.L2DomainExpressionApply ss domArgs unitArgs val ->
      L2.L2DomainExpressionApply ss
        <$> mapM (\(sdid, domExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalDomainExpression foreignMod foreignURL domExpr)
                 domArgs
        <*> mapM (\(sdid, unitExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalUnitExpression foreignMod foreignURL unitExpr)
                 unitArgs
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL val
    L2.L2DomainFunctionEvaluate ss dfid args ->
      L2.L2DomainFunctionEvaluate ss
        <$> recursivelyImportExternalDomainFunction foreignMod foreignURL dfid
        <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) args
    L2.L2DomainVariableRef ss sdid ->
      L2.L2DomainVariableRef ss <$> (recursivelyImportExternalScopedDomain foreignMod foreignURL sdid)
    L2.L2DomainExpressionLambda ss scopedDoms scopedUnits uConstraints dEqs dRels dex ->
      L2.L2DomainExpressionLambda ss
        <$> mapM (\(d, k) ->
                   (,)
                     <$> recursivelyImportExternalScopedDomain foreignMod foreignURL d
                     <*> pure k) scopedDoms
        <*> mapM (recursivelyImportExternalScopedUnit foreignMod foreignURL) scopedUnits
        <*> mapM (\(uex1, uex2) -> (,)
                    <$> recursivelyImportExternalUnitExpression foreignMod foreignURL uex1
                    <*> recursivelyImportExternalUnitExpression foreignMod foreignURL uex2) uConstraints
        <*> mapM (\(dex1, dex2) -> (,)
                    <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dex1
                    <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex2) dEqs
        <*> mapM (\(cls, dexs) -> (,)
                      <$> recursivelyImportExternalClassExpression foreignMod foreignURL cls
                      <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) dexs
                 ) dRels
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex
recursivelyImportExternalDomainExpression foreignMod foreignURL targetEx =
  case targetEx of
    L2.L2DomainExpressionProduct ss l ->
      L2.L2DomainExpressionProduct ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionDisjointUnion ss l ->
      L2.L2DomainExpressionDisjointUnion ss <$>
        recursivelyImportExternalLabelledDomains foreignMod foreignURL l
    L2.L2DomainExpressionFieldSignature ss dd dcd ->
      L2.L2DomainExpressionFieldSignature ss
        <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dd
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dcd
    L2.L2DomainExpressionReal ss u ->
      L2.L2DomainExpressionReal ss
        <$> recursivelyImportExternalUnitExpression foreignMod foreignURL u
    L2.L2DomainExpressionApply ss domArgs unitArgs val ->
      L2.L2DomainExpressionApply ss
        <$> mapM (\(sdid, domExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalDomainExpression foreignMod foreignURL domExpr)
                 domArgs
        <*> mapM (\(sdid, unitExpr) ->
                   (,) sdid
                       <$> recursivelyImportExternalUnitExpression foreignMod foreignURL unitExpr)
                 unitArgs
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL val
    L2.L2DomainFunctionEvaluate ss dfid args ->
      L2.L2DomainFunctionEvaluate ss
        <$> recursivelyImportExternalDomainFunction foreignMod foreignURL dfid
        <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) args
    L2.L2DomainVariableRef ss sdid ->
      L2.L2DomainVariableRef ss <$> (recursivelyImportExternalScopedDomain foreignMod foreignURL sdid)
    L2.L2DomainExpressionLambda ss scopedDoms scopedUnits uConstraints dEqs dRels dex ->
      L2.L2DomainExpressionLambda ss
        <$> mapM (\(d, k) ->
                   (,)
                     <$> recursivelyImportExternalScopedDomain foreignMod foreignURL d
                     <*> pure k) scopedDoms
        <*> mapM (recursivelyImportExternalScopedUnit foreignMod foreignURL) scopedUnits
        <*> mapM (\(uex1, uex2) -> (,)
                    <$> recursivelyImportExternalUnitExpression foreignMod foreignURL uex1
                    <*> recursivelyImportExternalUnitExpression foreignMod foreignURL uex2) uConstraints
        <*> mapM (\(dex1, dex2) -> (,)
                    <$> recursivelyImportExternalDomainExpression foreignMod foreignURL dex1
                    <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex2) dEqs
        <*> mapM (\(cls, dexs) -> (,)
                      <$> recursivelyImportExternalClassExpression foreignMod foreignURL cls
                      <*> mapM (recursivelyImportExternalDomainExpression foreignMod foreignURL) dexs
                 ) dRels
        <*> recursivelyImportExternalDomainExpression foreignMod foreignURL dex