Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print unboxed expressions correctly #649

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,8 @@ Unboxed sum pattern matching.
```haskell
{-# LANGUAGE UnboxedSums #-}

f (# x | | | #) = undefined
f (# (# n, _ #) | #) = (# n | #)
f (# | b #) = (# | b #)
```

Pattern matching against a infix constructor with a module name prefix
Expand Down
13 changes: 10 additions & 3 deletions src/HIndent/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,14 @@ prettyHsExpr (ExplicitTuple _ full _) = horizontal <-|> vertical
fmap (\e -> unless (isMissing e) (space |=> pretty e)) full
isMissing Missing {} = True
isMissing _ = False
prettyHsExpr (ExplicitSum _ _ _ expr) =
unboxedParens $ spaced [string "|", pretty expr]
prettyHsExpr (ExplicitSum _ position numElem expr) = do
string "(#"
forM_ [1 .. numElem] $ \idx -> do
if idx == position
then string " " >> pretty expr >> string " "
else string " "
when (idx < numElem) $ string "|"
string "#)"
prettyHsExpr (HsCase _ cond arms) = do
string "case " |=> do
pretty cond
Expand Down Expand Up @@ -1258,7 +1264,8 @@ prettyPat (ParPat _ inner) = parens $ pretty inner
#endif
prettyPat (BangPat _ x) = string "!" >> pretty x
prettyPat (ListPat _ xs) = hList $ fmap pretty xs
prettyPat (TuplePat _ pats _) = hTuple $ fmap pretty pats
prettyPat (TuplePat _ pats Boxed) = hTuple $ fmap pretty pats
prettyPat (TuplePat _ pats Unboxed) = hUnboxedTuple $ fmap pretty pats
prettyPat (SumPat _ x position numElem) = do
string "(#"
forM_ [1 .. numElem] $ \idx -> do
Expand Down
1 change: 1 addition & 0 deletions src/HIndent/Pretty/Combinators/Lineup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module HIndent.Pretty.Combinators.Lineup
, hPromotedTuple
, -- * Unboxed tuples
hvUnboxedTuple'
, hUnboxedTuple
, -- * Unboxed sums
hvUnboxedSum'
, -- * Records
Expand Down