Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Language/PureScript/Pretty/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ]
Expand Down