diff --git a/src/Language/PureScript/Pretty/Types.hs b/src/Language/PureScript/Pretty/Types.hs index d24c9a3ae5..ad8ee7763d 100644 --- a/src/Language/PureScript/Pretty/Types.hs +++ b/src/Language/PureScript/Pretty/Types.hs @@ -74,6 +74,15 @@ prettyPrintRowWith tro open close = uncurry listToBox . toList [] prettyPrintRow :: Type -> String prettyPrintRow = render . prettyPrintRowWith defaultOptions '(' ')' +-- Treat `ProxyType t` in a similar way to the application of a type +-- constructor `@` to `t`, i.e: `@ t`, except that we don't render the unneeded +-- space. So we end up with `@t`. +proxyType :: Pattern () Type (Type, Type) +proxyType = mkPattern match + where + match (ProxyType t) = Just (TypeConstructor (Qualified Nothing (ProperName "@")), t) + match _ = Nothing + typeApp :: Pattern () Type (Type, Type) typeApp = mkPattern match where @@ -135,7 +144,6 @@ matchTypeAtom tro@TypeRenderOptions{troSuggesting = suggesting} = | otherwise = Just $ text $ T.unpack name ++ show s match REmpty = Just $ text "()" match row@RCons{} = Just $ prettyPrintRowWith tro '(' ')' row - match (ProxyType t) = Just $ text "@" <> typeAtomAsBox t match (BinaryNoParensType op l r) = Just $ typeAsBox l <> text " " <> typeAsBox op <> text " " <> typeAsBox r match (TypeOp op) = Just $ text $ T.unpack $ showQualified runOpName op @@ -145,7 +153,8 @@ matchType :: TypeRenderOptions -> Pattern () Type Box matchType tro = buildPrettyPrinter operators (matchTypeAtom tro) where operators :: OperatorTable () Type Box operators = - OperatorTable [ [ AssocL typeApp $ \f x -> keepSingleLinesOr (moveRight 2) f x ] + OperatorTable [ [ AssocL proxyType $ \p ty -> p <> ty ] + , [ AssocL typeApp $ \f x -> keepSingleLinesOr (moveRight 2) f x ] , [ AssocR appliedFunction $ \arg ret -> keepSingleLinesOr id arg (text rightArrow <> " " <> ret) ] , [ Wrap constrained $ \deps ty -> constraintsAsBox tro deps ty ] , [ Wrap forall_ $ \idents ty -> keepSingleLinesOr (moveRight 2) (text (forall' ++ " " ++ unwords idents ++ ".")) ty ]