sizeOf' cp (TEApp _ f args) = do
  env <- ask
  case controlPointFromExpr f (controlPoints env) of
    Just target -> do
      let targetData = controlPointData target
      argSizes <- mapM (sizeOf' cp) args
      let argEnv = map DataPos argSizes
      local (addData $ zip (map fst targetData) argEnv) $ sizeOf' cp f
    Nothing ->
      case constructorFromExpr f (constructors env) of
        Just constructor ->
          let argTypes = zip args (constructorParameters constructor)
              (nonRecArg, recArgs) = partition (\(e,t) -> t == NonRecursive) argTypes
          in case recArgs of
               []         -> return Min
               [(arg, _)] -> do size <- sizeOf' cp arg; return $ C size
               args       -> do sizes <- mapM (sizeOf' cp) (map fst recArgs)
                                return (Multiple $ map C sizes)
        Nothing -> throwError $ SizeError "Called function does not exist. This is a type checking issue."
sizeOf' cp (TEApp _ f args) = do
  env <- ask
  case controlPointFromExpr f (controlPoints env) of
    Just target -> do
      let targetData = controlPointData target
      argSizes <- mapM (sizeOf' cp) args
      let argEnv = map DataPos argSizes
      local (addData $ zip (map fst targetData) argEnv) $ sizeOf' cp f
    Nothing ->
      case constructorFromExpr f (constructors env) of
        Just constructor ->
          let argTypes = zip args (constructorParameters constructor)
              (nonRecArg, recArgs) = partition (\(e,t) -> t == NonRecursive) argTypes
          in case recArgs of
               []         -> return Min
               [(arg, _)] -> do size <- sizeOf' cp arg; return $ C size
               args       -> do sizes <- mapM (sizeOf' cp) (map fst recArgs)
                                return (Multiple $ map C sizes)
        Nothing -> throwError $ SizeError "Called function does not exist. This is a type checking issue."
sizeOf' cp (TEApp _ f args) = do
  env <- ask
  case controlPointFromExpr f (controlPoints env) of
    Just target -> do
      let targetData = controlPointData target
      argSizes <- mapM (sizeOf' cp) args
      let argEnv = map DataPos argSizes
      local (addData $ zip (map fst targetData) argEnv) $ sizeOf' cp f
    Nothing ->
      case constructorFromExpr f (constructors env) of
        Just constructor ->
          let argTypes = zip args (constructorParameters constructor)
              (nonRecArg, recArgs) = partition (\(e,t) -> t == NonRecursive) argTypes
          in case recArgs of
               []         -> return Min
               [(arg, _)] -> do size <- sizeOf' cp arg; return $ C size
               args       -> do sizes <- mapM (sizeOf' cp) (map fst recArgs)
                                return (Multiple $ map C sizes)
        Nothing -> throwError $ SizeError "Called function does not exist. This is a type checking issue."