Skip to content

Commit

Permalink
fix record update printing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Aug 22, 2024
1 parent 7298271 commit 13babbf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Juvix/Compiler/Backend/Isabelle/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ instance PrettyCode Expression where
ExprTuple x -> ppCode x
ExprList x -> ppCode x
ExprCons x -> ppCode x
ExprRecord x -> ppCode x
ExprRecord x -> ppRecord False x
ExprRecordUpdate x -> ppCode x
ExprLet x -> ppCode x
ExprIf x -> ppCode x
Expand Down Expand Up @@ -110,7 +110,7 @@ instance PrettyCode Binop where
instance PrettyCode RecordUpdate where
ppCode RecordUpdate {..} = do
r <- ppCode _recordUpdateRecord
fields <- ppCode _recordUpdateFields
fields <- ppRecord True _recordUpdateFields
return $ r <+> fields

instance PrettyCode LetClause where
Expand Down Expand Up @@ -155,14 +155,15 @@ instance (PrettyCode a) => PrettyCode (List a) where
elems <- mapM ppCode _listElements
return $ brackets $ hsep (punctuate comma elems)

instance (PrettyCode a) => PrettyCode (Record a) where
ppCode Record {..} = do
recName <- ppCode _recordName
names <- mapM (ppCode . fst) _recordFields
elems <- mapM (ppCode . snd) _recordFields
let names' = map (\n -> recName <> "." <> n) names
fields = zipWithExact (\n e -> n <+> "=" <+> e) names' elems
return $ "(|" <+> hsep (punctuate comma fields) <+> "|)"
ppRecord :: (PrettyCode a, Member (Reader Options) r) => Bool -> Record a -> Sem r (Doc Ann)
ppRecord bUpdate Record {..} = do
recName <- ppCode _recordName
names <- mapM (ppCode . fst) _recordFields
elems <- mapM (ppCode . snd) _recordFields
let names' = map (\n -> recName <> "." <> n) names
eq = if bUpdate then ":=" else "="
fields = zipWithExact (\n e -> n <+> eq <+> e) names' elems
return $ "(|" <+> hsep (punctuate comma fields) <+> "|)"

instance (PrettyCode a, HasAtomicity a) => PrettyCode (Cons a) where
ppCode Cons {..} = do
Expand All @@ -178,7 +179,7 @@ instance PrettyCode Pattern where
PatTuple x -> ppCode x
PatList x -> ppCode x
PatCons x -> ppCode x
PatRecord x -> ppCode x
PatRecord x -> ppRecord False x

instance PrettyCode ConstrApp where
ppCode ConstrApp {..} = do
Expand Down

0 comments on commit 13babbf

Please sign in to comment.