--}
- | null tt = ppr dc
- | otherwise = cparen (p >= app_prec)
- (ppr dc <+> sep (map (pprTerm app_prec) tt))
-
- where fixity = undefined
-
-pprTerm _ t = pprTerm1 t
-
-pprTerm1 Prim{value=words, ty=ty} = text$ repPrim (tyConAppTyCon ty) words
-pprTerm1 t@Term{} = pprTerm 0 t
-pprTerm1 Suspension{bound_to=Nothing} = char '_' -- <> ppr ct <> char '_'
-pprTerm1 Suspension{mb_ty=Just ty, bound_to=Just n}
- | Just _ <- splitFunTy_maybe ty = ptext SLIT("<function>")
- | otherwise = parens$ ppr n <> text "::" <> ppr ty
-
-
-cPprTerm :: forall m. Monad m => ((Int->Term->m SDoc)->[Int->Term->m (Maybe SDoc)]) -> Term -> m SDoc
+-} -- TODO Printing infix constructors properly
+ | null tt = return$ ppr dc
+ | Just (tc,_) <- splitNewTyConApp_maybe ty
+ , isNewTyCon tc
+ , Just new_dc <- maybeTyConSingleCon tc = do
+ real_value <- y 10 t{ty=repType ty}
+ return$ cparen (p >= app_prec) (ppr new_dc <+> real_value)
+ | otherwise = do
+ tt_docs <- mapM (y app_prec) tt
+ return$ cparen (p >= app_prec) (ppr dc <+> sep tt_docs)
+
+pprTermM y _ t = pprTermM1 y t
+pprTermM1 _ Prim{value=words, ty=ty} =
+ return$ text$ repPrim (tyConAppTyCon ty) words
+pprTermM1 y t@Term{} = panic "pprTermM1 - unreachable"
+pprTermM1 _ Suspension{bound_to=Nothing} = return$ char '_'
+pprTermM1 _ Suspension{mb_ty=Just ty, bound_to=Just n}
+ | Just _ <- splitFunTy_maybe ty = return$ ptext SLIT("<function>")
+ | otherwise = return$ parens$ ppr n <> text "::" <> ppr ty
+
+-- Takes a list of custom printers with a explicit recursion knot and a term,
+-- and returns the output of the first succesful printer, or the default printer
+cPprTerm :: forall m. Monad m =>
+ ((Int->Term->m SDoc)->[Int->Term->m (Maybe SDoc)]) -> Term -> m SDoc