+flattenExpr binds app@(App _ _) = do
+ -- Is this a data constructor application?
+ case CoreUtils.exprIsConApp_maybe app of
+ -- Is this a tuple construction?
+ Just (dc, args) -> if DataCon.isTupleCon dc
+ then
+ flattenBuildTupleExpr binds (dataConAppArgs dc args)
+ else
+ error $ "Data constructors other than tuples not supported: " ++ (showSDoc $ ppr app)
+ otherwise ->
+ -- Normal function application
+ let ((Var f), args) = collectArgs app in
+ flattenApplicationExpr binds (CoreUtils.exprType app) f args
+ where
+ flattenBuildTupleExpr = error $ "Tuple construction not supported: " ++ (showSDoc $ ppr app)
+ flattenApplicationExpr binds ty f args = error $ "Function application not supported: " ++ (showSDoc $ ppr app)
+