Skip to content

Commit b1793b8

Browse files
committed
Float mbSubstitution out, make pure
Format with fourmolu
1 parent 534414c commit b1793b8

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

booster/library/Booster/Syntax/Json/Internalise.hs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,33 @@ mkSubstitution initialSubst =
481481
)
482482
breakCycles
483483

484+
-- | Given a equality @'Term'@, decide if it can be interpreted as substitution.
485+
mbSubstitution ::
486+
Internal.Term -> InternalisedPredicate
487+
mbSubstitution = \case
488+
eq@(Internal.EqualsInt (Internal.Var x) e)
489+
| x `Set.member` freeVariables e -> boolPred eq
490+
| otherwise -> SubstitutionPred x e
491+
eq@(Internal.EqualsInt e (Internal.Var x))
492+
| x `Set.member` freeVariables e -> boolPred eq
493+
| otherwise -> SubstitutionPred x e
494+
eq@(Internal.EqualsK (Internal.KSeq _sortL (Internal.Var x)) (Internal.KSeq _sortR e)) ->
495+
do
496+
-- NB sorts do not have to agree! (could be subsorts)
497+
if (x `Set.member` freeVariables e)
498+
then boolPred eq
499+
else SubstitutionPred x e
500+
eq@(Internal.EqualsK (Internal.KSeq _sortL e) (Internal.KSeq _sortR (Internal.Var x))) ->
501+
do
502+
-- NB sorts do not have to agree! (could be subsorts)
503+
if (x `Set.member` freeVariables e)
504+
then boolPred eq
505+
else SubstitutionPred x e
506+
other ->
507+
boolPred other
508+
where
509+
boolPred = BoolPred . Internal.Predicate
510+
484511
internalisePred ::
485512
Flag "alias" ->
486513
Flag "subsorts" ->
@@ -542,9 +569,9 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
542569
case (argS, a, b) of
543570
-- for "true" #Equals P, check whether P is in fact a substitution
544571
(Internal.SortBool, Internal.TrueBool, x) ->
545-
mapM mbSubstitution [x]
572+
pure [mbSubstitution x]
546573
(Internal.SortBool, x, Internal.TrueBool) ->
547-
mapM mbSubstitution [x]
574+
pure [mbSubstitution x]
548575
-- we could also detect NotBool (NEquals _) in "false" #Equals P
549576
(Internal.SortBool, Internal.FalseBool, x) ->
550577
pure [BoolPred $ Internal.Predicate $ Internal.NotBool x]
@@ -602,33 +629,6 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
602629
throwE (IncompatibleSorts (map externaliseSort [s1, s2]))
603630
zipWithM_ go args1 args2
604631

605-
mbSubstitution :: Internal.Term -> Except PatternError InternalisedPredicate
606-
mbSubstitution = \case
607-
eq@(Internal.EqualsInt (Internal.Var x) e)
608-
| x `Set.member` freeVariables e -> pure $ boolPred eq
609-
| otherwise -> pure $ SubstitutionPred x e
610-
eq@(Internal.EqualsInt e (Internal.Var x))
611-
| x `Set.member` freeVariables e -> pure $ boolPred eq
612-
| otherwise -> pure $ SubstitutionPred x e
613-
eq@(Internal.EqualsK (Internal.KSeq _sortL (Internal.Var x)) (Internal.KSeq _sortR e)) ->
614-
do
615-
-- NB sorts do not have to agree! (could be subsorts)
616-
pure $
617-
if (x `Set.member` freeVariables e)
618-
then boolPred eq
619-
else SubstitutionPred x e
620-
eq@(Internal.EqualsK (Internal.KSeq _sortL e) (Internal.KSeq _sortR (Internal.Var x))) ->
621-
do
622-
-- NB sorts do not have to agree! (could be subsorts)
623-
pure $
624-
if (x `Set.member` freeVariables e)
625-
then boolPred eq
626-
else SubstitutionPred x e
627-
other ->
628-
pure $ boolPred other
629-
630-
boolPred = BoolPred . Internal.Predicate
631-
632632
----------------------------------------
633633

634634
-- for use with withAssoc

0 commit comments

Comments
 (0)