From 3354c68ec6c90bbccc0f361aa7973eeb75ea229c Mon Sep 17 00:00:00 2001 From: Vladislav Zavialov Date: Mon, 2 Dec 2019 23:10:33 +0300 Subject: Pretty-printing of the * kind Before this patch, GHC always printed the * kind unparenthesized. This led to two issues: 1. Sometimes GHC printed invalid or incorrect code. For example, GHC would print: type F @* x = x when it meant to print: type F @(*) x = x In the former case, instead of a kind application we were getting a type operator (@*). 2. Sometimes GHC printed kinds that were correct but hard to read. Should Either * Int be read as Either (*) Int or as (*) Either Int ? This depends on whether -XStarIsType is enabled, but it would be easier if we didn't have to check for the flag when reading the code. We can solve both problems by assigning (*) a different precedence. Note that Haskell98 kinds are not affected: ((* -> *) -> *) -> * does NOT become (((*) -> (*)) -> (*)) -> (*) The parentheses are added when (*) is used in a function argument position: F * * * becomes F (*) (*) (*) F A * B becomes F A (*) B Proxy * becomes Proxy (*) a * -> * becomes a (*) -> * --- compiler/utils/Outputable.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'compiler/utils') diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index bbc365b774..0dda99020f 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -28,7 +28,7 @@ module Outputable ( semi, comma, colon, dcolon, space, equals, dot, vbar, arrow, larrow, darrow, arrowt, larrowt, arrowtt, larrowtt, lparen, rparen, lbrack, rbrack, lbrace, rbrace, underscore, - blankLine, forAllLit, kindType, bullet, + blankLine, forAllLit, bullet, (<>), (<+>), hcat, hsep, ($$), ($+$), vcat, sep, cat, @@ -91,7 +91,7 @@ import GhcPrelude import {-# SOURCE #-} DynFlags( DynFlags, hasPprDebug, hasNoDebugOutput, targetPlatform, pprUserLength, pprCols, - useUnicode, useUnicodeSyntax, useStarIsType, + useUnicode, useUnicodeSyntax, shouldUseColor, unsafeGlobalDynFlags, shouldUseHexWordLiterals ) import {-# SOURCE #-} Module( UnitId, Module, ModuleName, moduleName ) @@ -649,12 +649,6 @@ rbrace = docToSDoc $ Pretty.rbrace forAllLit :: SDoc forAllLit = unicodeSyntax (char '∀') (text "forall") -kindType :: SDoc -kindType = sdocWithDynFlags $ \dflags -> - if useStarIsType dflags - then unicodeSyntax (char '★') (char '*') - else text "Type" - bullet :: SDoc bullet = unicode (char '•') (char '*') -- cgit v1.2.1