- -- is always exactly CoHole
- | CoLet (LHsBinds Id) -- let binds in []
- -- (ould be nicer to be core bindings)
-
-instance Outputable ExprCoFn where
- ppr co_fn = pprCoFn (ptext SLIT("<>")) co_fn
-
-pprCoFn it CoHole = it
-pprCoFn it (CoCompose f1 f2) = pprCoFn (pprCoFn it f2) f1
-pprCoFn it (ExprCoFn co) = it <+> ptext SLIT("`cast`") <+> pprParendType co
-pprCoFn it (CoApp id) = it <+> ppr id
-pprCoFn it (CoTyApp ty) = it <+> ptext SLIT("@") <+> pprParendType ty
-pprCoFn it (CoLam id) = ptext SLIT("\\") <> pprBndr LambdaBind id <> dot <+> it
-pprCoFn it (CoTyLam tv) = ptext SLIT("/\\") <> pprBndr LambdaBind tv <> dot <+> it
-pprCoFn it (CoLet binds) = sep [ptext SLIT("let") <+> braces (ppr binds), it]
-
-(<.>) :: ExprCoFn -> ExprCoFn -> ExprCoFn
-CoHole <.> c = c
-c <.> CoHole = c
-c1 <.> c2 = c1 `CoCompose` c2
-
-mkCoTyApps :: [Type] -> ExprCoFn
-mkCoTyApps tys = mk_co_fn CoTyApp (reverse tys)
-
-mkCoApps :: [Id] -> ExprCoFn
-mkCoApps ids = mk_co_fn CoApp (reverse ids)
-
-mkCoTyLams :: [TyVar] -> ExprCoFn
-mkCoTyLams ids = mk_co_fn CoTyLam ids
-
-mkCoLams :: [Id] -> ExprCoFn
-mkCoLams ids = mk_co_fn CoLam ids
-
-mk_co_fn :: (a -> ExprCoFn) -> [a] -> ExprCoFn
-mk_co_fn f as = foldr (CoCompose . f) CoHole as
-
-idCoercion :: ExprCoFn
-idCoercion = CoHole
-
-isIdCoercion :: ExprCoFn -> Bool
-isIdCoercion CoHole = True
-isIdCoercion other = False
+ -- is always exactly WpHole
+ | WpLet (LHsBinds Id) -- let binds in []
+ -- (would be nicer to be core bindings)
+
+instance Outputable HsWrapper where
+ ppr co_fn = pprHsWrapper (ptext SLIT("<>")) co_fn
+
+pprHsWrapper :: SDoc -> HsWrapper -> SDoc
+pprHsWrapper it wrap =
+ let
+ help it WpHole = it
+ help it (WpCompose f1 f2) = help (help it f2) f1
+ help it (WpCo co) = sep [it, nest 2 (ptext SLIT("`cast`") <+> pprParendType co)]
+ help it (WpApp id) = sep [it, nest 2 (ppr id)]
+ help it (WpTyApp ty) = sep [it, ptext SLIT("@") <+> pprParendType ty]
+ help it (WpLam id) = sep [ptext SLIT("\\") <> pprBndr LambdaBind id <> dot, it]
+ help it (WpTyLam tv) = sep [ptext SLIT("/\\") <> pprBndr LambdaBind tv <> dot, it]
+ help it (WpLet binds) = sep [ptext SLIT("let") <+> braces (ppr binds), it]
+ help it WpInline = sep [ptext SLIT("_inline_me_"), it]
+ in
+ -- in debug mode, print the wrapper
+ -- otherwise just print what's inside
+ getPprStyle (\ s -> if debugStyle s then (help it wrap) else it)
+
+(<.>) :: HsWrapper -> HsWrapper -> HsWrapper
+WpHole <.> c = c
+c <.> WpHole = c
+c1 <.> c2 = c1 `WpCompose` c2
+
+mkWpTyApps :: [Type] -> HsWrapper
+mkWpTyApps tys = mk_co_fn WpTyApp (reverse tys)
+
+mkWpApps :: [Id] -> HsWrapper
+mkWpApps ids = mk_co_fn WpApp (reverse ids)
+
+mkWpTyLams :: [TyVar] -> HsWrapper
+mkWpTyLams ids = mk_co_fn WpTyLam ids
+
+mkWpLams :: [Id] -> HsWrapper
+mkWpLams ids = mk_co_fn WpLam ids
+
+mk_co_fn :: (a -> HsWrapper) -> [a] -> HsWrapper
+mk_co_fn f as = foldr (WpCompose . f) WpHole as
+
+idHsWrapper :: HsWrapper
+idHsWrapper = WpHole
+
+isIdHsWrapper :: HsWrapper -> Bool
+isIdHsWrapper WpHole = True
+isIdHsWrapper other = False