
#12618: Add saturated constructor applications to Core -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): Using a pattern synonynm works always; the problem is that the code should be generic in the binder, but then we have no way of knowing the binder’s type. But for what it’s worth: It seems to compile with this change: {{{ data Expr b = Var Id | Lit Literal -- | App (Expr b) (Arg b) | Apps (Expr b) Arity [Expr b] | Lam b (Expr b) | Let (Bind b) (Expr b) | Case (Expr b) b Type [Alt b] -- See #case_invariant# | Cast (Expr b) Coercion | Tick (Tickish Id) (Expr b) | Type Type | Coercion Coercion deriving Data unpackArgs :: Expr b -> Arity -> [Expr b] -> [Expr b] unpackArgs _ _ l = l -- do something smarter here packArgs :: Expr b -> [Expr b] -> [Expr b] packArgs _ l = l -- do something smarter here popArg :: Expr b -> Maybe (Expr b, Expr b) popArg (Apps e a xs) = case unpackArgs e a xs of [x] -> Just (e, x) xs -> Just (Apps e (a-1) (packArgs e (init xs)), last xs) popArg _ = Nothing pattern App e1 e2 <- (popArg -> Just (e1, e2)) where App e1 e2 | (f, args) <- collectArgs e1 = Apps f (length args +1) (packArgs f (args ++ [e2])) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12618#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler