git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1527 from purescript/1524

Fix #1524, render kinds as single line strings.

commitc3a63abda7a6e4c75e7ee827cd82a69936143fda authorPhil Freeman <paf31@cantab.net> dateSat 17 Oct 2015, 14:27 (11 years ago) parent3d1c544ad0dcb7
3 files changed+17−22
src/Language/PureScript/Errors.hs+4−4 src/Language/PureScript/Pretty/Kinds.hs+12−17 src/Language/PureScript/Pretty/Types.hs+1−1
src/Language/PureScript/Errors.hs+4−4
@@ -447,7 +447,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
447447 ]
448448 renderSimpleErrorMessage (InfiniteKind ki) =
449449 paras [ line "An infinite kind was inferred for a type: "
450− , indent $ kindAsBox ki
450+ , indent $ line $ prettyPrintKind ki
451451 ]
452452 renderSimpleErrorMessage (MultipleFixities name) =
453453 line $ "Multiple fixity declarations for " ++ showIdent name
@@ -542,9 +542,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
542542 ]
543543 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544544 paras [ line "Cannot unify kind"
545− , indent $ kindAsBox k1
545+ , indent $ line $ prettyPrintKind k1
546546 , line "with kind"
547− , indent $ kindAsBox k2
547+ , indent $ line $ prettyPrintKind k2
548548 ]
549549 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550550 paras [ line "Cannot unify constrained type"
@@ -604,7 +604,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
604604 , line "The error arises from the type"
605605 , indent $ typeAsBox ty
606606 , line "having the kind"
607− , indent $ kindAsBox kind
607+ , indent $ line $ prettyPrintKind kind
608608 , line "instead."
609609 ]
610610 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
src/Language/PureScript/Pretty/Kinds.hs+12−17
@@ -14,8 +14,7 @@
1414-----------------------------------------------------------------------------
1515
1616module Language.PureScript.Pretty.Kinds (
17− prettyPrintKind,
18− kindAsBox
17+ prettyPrintKind
1918) where
2019
2120import Data.Maybe (fromMaybe)
@@ -24,15 +23,14 @@ import Control.Arrow (ArrowPlus(..))
2423import Control.PatternArrows
2524
2625import Language.PureScript.Kinds
26+import Language.PureScript.Pretty.Common
2727
28−import Text.PrettyPrint.Boxes (Box(), text, render, (<>))
29−
30−typeLiterals :: Pattern () Kind Box
28+typeLiterals :: Pattern () Kind String
3129typeLiterals = mkPattern match
3230 where
33− match Star = Just $ text "*"
34− match Bang = Just $ text "!"
35− match (KUnknown u) = Just $ text $ 'u' : show u
31+ match Star = Just "*"
32+ match Bang = Just "!"
33+ match (KUnknown u) = Just $ 'u' : show u
3634 match _ = Nothing
3735
3836matchRow :: Pattern () Kind ((), Kind)
@@ -49,15 +47,12 @@ funKind = mkPattern match
4947
5048-- | Generate a pretty-printed string representing a Kind
5149prettyPrintKind :: Kind -> String
52−prettyPrintKind = render . kindAsBox
53−
54−kindAsBox :: Kind -> Box
55−kindAsBox = fromMaybe (error "Incomplete pattern") . pattern matchKind ()
50+prettyPrintKind = fromMaybe (error "Incomplete pattern") . pattern matchKind ()
5651 where
57− matchKind :: Pattern () Kind Box
58− matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap ((text "(" <>) . (<> text ")")) matchKind)
52+ matchKind :: Pattern () Kind String
53+ matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchKind)
5954
60− operators :: OperatorTable () Kind Box
55+ operators :: OperatorTable () Kind String
6156 operators =
62− OperatorTable [ [ Wrap matchRow $ \_ k -> text "# " <> k]
63− , [ AssocR funKind $ \arg ret -> arg <> text " -> " <> ret ] ]
57+ OperatorTable [ [ Wrap matchRow $ \_ k -> "# " ++ k]
58+ , [ AssocR funKind $ \arg ret -> arg ++ " -> " ++ ret ] ]
src/Language/PureScript/Pretty/Types.hs+1−1
@@ -126,7 +126,7 @@ matchType = buildPrettyPrinter operators matchTypeAtom
126126 , [ AssocR appliedFunction $ \arg ret -> (arg <> text " ") `before` (text "-> " <> ret)
127127 ]
128128 , [ Wrap forall_ $ \idents ty -> text ("forall " ++ unwords idents ++ ". ") <> ty ]
129− , [ Wrap kinded $ \k ty -> ty `before` (text " :: " <> kindAsBox k) ]
129+ , [ Wrap kinded $ \k ty -> ty `before` (text (" :: " ++ prettyPrintKind k)) ]
130130 ]
131131
132132forall_ :: Pattern () Type ([String], Type)