{-
Given a list of array names and index expressions, an expression to subtitute,
and an expression e, check if e is an array name in our list,
and if it is, replace it with the approprate RepBy expression
to denote a substitution
-}
subOneLevelArr :: [(Name, Expression)] -> Expression -> Expression -> Expression
subOneLevelArr nameIndexPairs subExpr e@(EName varName) =
   let
    nameIndList = filter (\(n,_) -> n == varName) nameIndexPairs
  in foldr (\(_,i) expSoFar -> RepBy expSoFar i subExpr) e nameIndList
subOneLevelArr :: [(Name, Expression)] -> Expression -> Expression -> Expression
subOneLevelArr nameIndexPairs subExpr e@(EName varName) =
   let
    nameIndList = filter (\(n,_) -> n == varName) nameIndexPairs
  in foldr (\(_,i) expSoFar -> RepBy expSoFar i subExpr) e nameIndList
subOneLevelArr nameIndexPairs subExpr e@(EName varName) =
   let
    nameIndList = filter (\(n,_) -> n == varName) nameIndexPairs
  in foldr (\(_,i) expSoFar -> RepBy expSoFar i subExpr) e nameIndList