Make pretty printing properly parenthesize higher order functions.
Not the best implementation, but it is simple and works well.
commitf87e316847077d1689e023283431aad901645a15
authorEvan Czaplicki <evan@Evans-MacBook-Air.local>
dateTue 9 Jul 2013, 21:59 (13 years ago)
parent497d478
compiler/Type/Type.hs+4−1
@@ -134,7 +134,10 @@ instance Pretty a => Pretty (Term1 a) where
134134 pretty term =
135135 case term of
136136 App1 f x -> pretty f <+> pretty x
137− Fun1 arg body -> pretty arg <+> P.text "->" <+> pretty body
137+ Fun1 arg body -> formattedArg <+> P.text "->" <+> pretty body
138+ where
139+ prettyArg = pretty arg
140+ formattedArg = parensIf ("->" `List.isInfixOf` P.render prettyArg) prettyArg
138141 Var1 x -> pretty x
139142 EmptyRecord1 -> P.braces P.empty
140143 Record1 fields ext ->