1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

Fix record update formatting (#2315)

* Closes #2287
This commit is contained in:
Łukasz Czajka 2023-08-28 13:11:26 +02:00 committed by GitHub
parent 227a51a56d
commit e8fa77a58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 12 deletions

View File

@ -201,7 +201,19 @@ instance (SingI s) => PrettyPrint (PatternAtoms s) where
ppCode (PatternAtoms ps _) = hsep (ppCode <$> ps)
instance (SingI s) => PrettyPrint (ExpressionAtoms s) where
ppCode as = hsep (ppCode <$> as ^. expressionAtoms)
ppCode ::
forall r.
(Members '[ExactPrint, Reader Options] r) =>
ExpressionAtoms s ->
Sem r ()
ppCode as = go (toList $ as ^. expressionAtoms)
where
go :: [ExpressionAtom s] -> Sem r ()
go = \case
[] -> return ()
[x] -> ppCode x
(x : xs@(AtomRecordUpdate {} : _)) -> ppCode x >> go xs
(x : xs) -> ppCode x >> space >> go xs
instance (SingI s) => PrettyPrint (Initializer s) where
ppCode Initializer {..} = do

View File

@ -72,11 +72,16 @@ ppUChain (UChain opFix f links) = do
pp <- asks (^. apePP)
let f' = ppLinkExpr fx f
args = hsep (fmap pp links)
f' <+> args
f' <> sp <> args
where
fx :: Precedence
fx = opFix ^. fixityPrecedence
sp :: Sem r ()
sp = case fx of
PrecUpdate -> return ()
_ -> space
ppLinkExpr ::
(Members '[Reader (ApeParams a), ExactPrint] r) => Precedence -> Cape a -> Sem r ()
ppLinkExpr opFix e = parensIf cond (ppCape e)

View File

@ -17,21 +17,20 @@ type Pair (A B : Type) :=
};
mf : Pair (Pair Bool (List Nat)) (List Nat) → Bool
| mkPair@{fst := mkPair@{fst; snd := nil}; snd := zero :: _} := fst
| mkPair@{fst := mkPair@{fst; snd := nil};
snd := zero :: _} := fst
| _ := false;
main : Triple Nat Nat Nat :=
let
p : Triple Nat Nat Nat := mkTriple 2 2 2;
p' :
Triple Nat Nat Nat :=
p @Triple{
fst := fst + 1;
snd := snd * 3 + thd + fst
};
f :
Triple Nat Nat Nat -> Triple Nat Nat Nat :=
(@Triple{fst := fst * 10});
p' : Triple Nat Nat Nat :=
p@Triple{
fst := fst + 1;
snd := snd * 3 + thd + fst
};
f : Triple Nat Nat Nat -> Triple Nat Nat Nat :=
(@Triple{fst := fst * 10});
in if
(mf (mkPair (fst := mkPair true nil; snd := 0 :: nil)))
(f p')