git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update pretty printer for Kinds
df1ce78Harry Garrood
src/Language/PureScript/Pretty/Kinds.hs+14−11
@@ -10,6 +10,7 @@ import Prelude.Compat
10import Control.Arrow (ArrowPlus(..))
10import Control.Arrow (ArrowPlus(..))
11import Control.PatternArrows as PA
11import Control.PatternArrows as PA
12
12
13+import Data.Monoid ((<>))
13import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
14import qualified Data.Text as T
15import qualified Data.Text as T
15import Data.Text (Text)
16import Data.Text (Text)
@@ -19,11 +20,15 @@ import Language.PureScript.Kinds
19import Language.PureScript.Names
20import Language.PureScript.Names
20import Language.PureScript.Pretty.Common
21import Language.PureScript.Pretty.Common
21
22
22−typeLiterals :: Pattern () Kind String
23+typeLiterals :: Pattern () Kind Text
23typeLiterals = mkPattern match
24typeLiterals = mkPattern match
24 where
25 where
25− match (KUnknown u) = Just $ 'u' : show u
26+ match (KUnknown u) =
27+ Just $ T.cons 'k' (T.pack (show u))
28+ match (NamedKind name) =
29+ Just $ if isQualifiedWith (moduleNameFromString "Prim") name
30+ then runProperName (disqualify name)
26− match (NamedKind name) = Just $ T.unpack (showQualified runProperName name)
31+ else showQualified runProperName name
27 match _ = Nothing
32 match _ = Nothing
28
33
29matchRow :: Pattern () Kind ((), Kind)
34matchRow :: Pattern () Kind ((), Kind)
@@ -41,15 +46,13 @@ funKind = mkPattern match
41-- | Generate a pretty-printed string representing a Kind
46-- | Generate a pretty-printed string representing a Kind
42prettyPrintKind :: Kind -> Text
47prettyPrintKind :: Kind -> Text
43prettyPrintKind
48prettyPrintKind
44− -- TODO(Christoph): get rid of T.pack
45− = T.pack
46− . fromMaybe (internalError "Incomplete pattern")
49+ = fromMaybe (internalError "Incomplete pattern")
47 . PA.pattern matchKind ()
50 . PA.pattern matchKind ()
48 where
51 where
49− matchKind :: Pattern () Kind String
52+ matchKind :: Pattern () Kind Text
50− matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchKind)
53+ matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parensT matchKind)
51
54
52− operators :: OperatorTable () Kind String
55+ operators :: OperatorTable () Kind Text
53 operators =
56 operators =
54− OperatorTable [ [ Wrap matchRow $ \_ k -> "# " ++ k]
57+ OperatorTable [ [ Wrap matchRow $ \_ k -> "# " <> k]
55− , [ AssocR funKind $ \arg ret -> arg ++ " -> " ++ ret ] ]
58+ , [ AssocR funKind $ \arg ret -> arg <> " -> " <> ret ] ]