on master help sign in
Print out tuple types without unnecessary parens
c7355f8Evan Czaplicki
src/Reporting/Render/Type.hs+16−7
@@ -191,15 +191,15 @@ diff localizer context leftType rightType =
191 (Type.App (Type.Type leftName) leftArgs, Type.App (Type.Type rightName) rightArgs) ->
191 (Type.App (Type.Type leftName) leftArgs, Type.App (Type.Type rightName) rightArgs) ->
192 if leftName /= rightName || length leftArgs /= length rightArgs then
192 if leftName /= rightName || length leftArgs /= length rightArgs then
193 difference
193 difference
194− (docApp localizer context leftName (map (docType localizer App) leftArgs))
194+ (docApp localizer context leftName leftArgs)
195− (docApp localizer context rightName (map (docType localizer App) rightArgs))
195+ (docApp localizer context rightName rightArgs)
196
196
197 else
197 else
198 let
198 let
199 subContext =
199 subContext =
200 if Var.isTuple leftName then None else App
200 if Var.isTuple leftName then None else App
201 in
201 in
202− docApp localizer context leftName
202+ docAppHelp localizer context leftName
203 <$> sequenceA (zipWith (go subContext) leftArgs rightArgs)
203 <$> sequenceA (zipWith (go subContext) leftArgs rightArgs)
204
204
205 (Type.App _ _, Type.App _ _) ->
205 (Type.App _ _, Type.App _ _) ->
@@ -216,7 +216,7 @@ diff localizer context leftType rightType =
216 diffRecord localizer leftFields leftExt rightFields rightExt
216 diffRecord localizer leftFields leftExt rightFields rightExt
217
217
218 (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
218 (Type.Aliased leftName leftArgs _, Type.Aliased rightName rightArgs _) | leftName == rightName ->
219− docApp localizer context leftName
219+ docAppHelp localizer context leftName
220 <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
220 <$> sequenceA (zipWith (go App) (map snd leftArgs) (map snd rightArgs))
221
221
222 (Type.Aliased _ args real, _) ->
222 (Type.Aliased _ args real, _) ->
@@ -387,7 +387,7 @@ docType localizer context tipe =
387 varToDoc localizer name
387 varToDoc localizer name
388
388
389 Type.App (Type.Type name) args ->
389 Type.App (Type.Type name) args ->
390− docApp localizer context name (map (docType localizer App) args)
390+ docApp localizer context name args
391
391
392 Type.App _ _ ->
392 Type.App _ _ ->
393 error "type applications should start with a type atom"
393 error "type applications should start with a type atom"
@@ -402,7 +402,7 @@ docType localizer context tipe =
402 (fmap text ext)
402 (fmap text ext)
403
403
404 Type.Aliased name args _ ->
404 Type.Aliased name args _ ->
405− docApp localizer context name (map (docType localizer App . snd) args)
405+ docApp localizer context name (map snd args)
406
406
407
407
408
408
@@ -426,8 +426,17 @@ docLambda context docs =
426
426
427
427
428
428
429−docApp :: Localizer -> Context -> Var.Canonical -> [Doc] -> Doc
429+docApp :: Localizer -> Context -> Var.Canonical -> [Type.Canonical] -> Doc
430docApp localizer context name args =
430docApp localizer context name args =
431+ let
432+ argContext =
433+ if Var.isTuple name then None else App
434+ in
435+ docAppHelp localizer context name (map (docType localizer argContext) args)
436+
437+
438+docAppHelp :: Localizer -> Context -> Var.Canonical -> [Doc] -> Doc
439+docAppHelp localizer context name args =
431 if Var.isTuple name then
440 if Var.isTuple name then
432 sep
441 sep
433 [ cat (zipWith (<+>) (lparen : repeat comma) args)
442 [ cat (zipWith (<+>) (lparen : repeat comma) args)