Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit a45c029

Browse files
committed
Simplify prettyCore.go.
1 parent d998f66 commit a45c029

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

semantic-core/src/Data/Core/Pretty.hs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,15 @@ inParens amount go = do
5656
pure (encloseIf (amount >= prec) (symbol "(") (symbol ")") body)
5757

5858
prettyCore :: Style -> Term Core User -> AnsiDoc
59-
prettyCore style = run . runReader @Prec 0 . go (pure . name)
60-
where go :: (Member (Reader Prec) sig, Carrier sig m) => (a -> m AnsiDoc) -> Term Core a -> m AnsiDoc
61-
go var = \case
62-
Var v -> var v
59+
prettyCore style = run . runReader @Prec 0 . go
60+
where go = \case
61+
Var v -> pure (name v)
6362
Term t -> case t of
6463
Let a -> pure $ keyword "let" <+> name a
6564
a :>> b -> do
6665
prec <- ask @Prec
67-
fore <- with 12 (go var a)
68-
aft <- with 12 (go var b)
66+
fore <- with 12 (go a)
67+
aft <- with 12 (go b)
6968

7069
let open = symbol ("{" <> softline)
7170
close = symbol (softline <> "}")
@@ -76,37 +75,37 @@ prettyCore style = run . runReader @Prec 0 . go (pure . name)
7675

7776
Lam n f -> inParens 11 $ do
7877
(x, body) <- bind n f
79-
pure (lambda <> x <+> arrow <+> body)
78+
pure (lambda <> name x <+> arrow <+> body)
8079

8180
Frame -> pure $ primitive "frame"
8281
Unit -> pure $ primitive "unit"
8382
Bool b -> pure $ primitive (if b then "true" else "false")
8483
String s -> pure . strlit $ Pretty.viaShow s
8584

86-
f :$ x -> inParens 11 $ (<+>) <$> go var f <*> go var x
85+
f :$ x -> inParens 11 $ (<+>) <$> go f <*> go x
8786

8887
If con tru fal -> do
89-
con' <- "if" `appending` go var con
90-
tru' <- "then" `appending` go var tru
91-
fal' <- "else" `appending` go var fal
88+
con' <- "if" `appending` go con
89+
tru' <- "then" `appending` go tru
90+
fal' <- "else" `appending` go fal
9291
pure $ Pretty.sep [con', tru', fal']
9392

94-
Load p -> "load" `appending` go var p
95-
Edge Lexical n -> "lexical" `appending` go var n
96-
Edge Import n -> "import" `appending` go var n
93+
Load p -> "load" `appending` go p
94+
Edge Lexical n -> "lexical" `appending` go n
95+
Edge Import n -> "import" `appending` go n
9796
item :. body -> inParens 4 $ do
98-
f <- go var item
99-
g <- go var body
97+
f <- go item
98+
g <- go body
10099
pure (f <> symbol "." <> g)
101100

102101
lhs := rhs -> inParens 3 $ do
103-
f <- go var lhs
104-
g <- go var rhs
102+
f <- go lhs
103+
g <- go rhs
105104
pure (f <+> symbol "=" <+> g)
106105

107106
-- Annotations are not pretty-printed, as it lowers the signal/noise ratio too profoundly.
108-
Ann _ c -> go var c
109-
where bind (Ignored x) f = let x' = name x in (,) x' <$> go (incr (const (pure x')) var) (fromScope sequenceA f)
107+
Ann _ c -> go c
108+
where bind (Ignored x) f = (,) x <$> go (fromScope (incr (const (pure x)) id) f)
110109
lambda = case style of
111110
Unicode -> symbol "λ"
112111
Ascii -> symbol "\\"

0 commit comments

Comments
 (0)