@@ -121,21 +121,27 @@ constrained = mkPattern match
121 match _ = Nothing
121 match _ = Nothing
123matchTypeAtom :: Pattern () Type Box
123matchTypeAtom :: Pattern () Type Box
124−matchTypeAtom = typeLiterals <+> fmap ((`before` text ")") . (text "(" <>)) matchType
124+matchTypeAtom = typeLiterals <+> fmap ((`before` (text ")")) . (text "(" <>)) matchType
126matchType :: Pattern () Type Box
126matchType :: Pattern () Type Box
127matchType = buildPrettyPrinter operators matchTypeAtom
127matchType = buildPrettyPrinter operators matchTypeAtom
129 operators :: OperatorTable () Type Box
129 operators :: OperatorTable () Type Box
130 operators =
130 operators =
131− OperatorTable [ [ AssocL typeApp $ \f x -> f `beforeWithSpace` x ]
131+ OperatorTable [ [ AssocL typeApp $ \f x -> keepSingleLinesOr (moveRight 2) f x ]
132− , [ AssocR appliedFunction $ \arg ret -> (arg <> text " ") `before` (text "-> " <> ret)
132+ , [ AssocR appliedFunction $ \arg ret -> keepSingleLinesOr id arg (text "-> " <> ret) ]
134 , [ Wrap constrained $ \deps ty -> constraintsAsBox deps ty ]
133 , [ Wrap constrained $ \deps ty -> constraintsAsBox deps ty ]
135− , [ Wrap forall_ $ \idents ty -> text ("forall " ++ unwords idents ++ ". ") <> ty ]
134+ , [ Wrap forall_ $ \idents ty -> keepSingleLinesOr (moveRight 2) (text ("forall " ++ unwords idents ++ ".")) ty ]
136− , [ Wrap kinded $ \k ty -> ty `before` text (" :: " ++ prettyPrintKind k) ]
135+ , [ Wrap kinded $ \k ty -> keepSingleLinesOr (moveRight 2) ty (text (":: " ++ prettyPrintKind k)) ]
138+ -- If both boxes span a single line, keep them on the same line, or else
139+ -- use the specified function to modify the second box, then combine vertically.
140+ keepSingleLinesOr :: (Box -> Box) -> Box -> Box -> Box
141+ keepSingleLinesOr f b1 b2
142+ | rows b1 > 1 || rows b2 > 1 = vcat left [ b1, f b2 ]
143+ | otherwise = hcat top [ b1, text " ", b2]
139forall_ :: Pattern () Type ([String], Type)
145forall_ :: Pattern () Type ([String], Type)
140forall_ = mkPattern match
146forall_ = mkPattern match