@@ -25,14 +25,15 @@ import Data.List (partition)
25
25
import Data.List.NonEmpty as NE (NonEmpty , fromList )
26
26
import Data.Map (Map )
27
27
import Data.Map qualified as Map
28
+ import Data.Maybe (isNothing )
28
29
import Data.Sequence (Seq , (><) , pattern (:<|) , pattern (:|>) )
29
30
import Data.Sequence qualified as Seq
30
31
31
32
import Data.Set (Set )
32
33
import Data.Set qualified as Set
33
34
import Prettyprinter
34
35
35
- import Booster.Definition.Attributes.Base (KListDefinition , KMapDefinition )
36
+ import Booster.Definition.Attributes.Base (KListDefinition , KMapDefinition , KSetDefinition )
36
37
import Booster.Definition.Base
37
38
import Booster.Pattern.Base
38
39
import Booster.Pattern.Pretty
@@ -262,7 +263,7 @@ match1 Eval t1@KSet{} t2@Injection{}
262
263
match1 _ t1@ KSet {} t2@ Injection {} = failWith $ DifferentSymbols t1 t2
263
264
match1 _ t1@ KSet {} t2@ KMap {} = failWith $ DifferentSymbols t1 t2
264
265
match1 _ t1@ KSet {} t2@ KList {} = failWith $ DifferentSymbols t1 t2
265
- match1 _ t1@ KSet {} t2@ KSet {} = addIndeterminate t1 t2
266
+ match1 _ t1@ ( KSet def1 patElements patRest) t2@ ( KSet def2 subjElements subjRest) = if def1 == def2 then matchSets def1 patElements patRest subjElements subjRest else failWith $ DifferentSorts t1 t2
266
267
match1 _ t1@ KSet {} t2@ ConsApplication {} = failWith $ DifferentSymbols t1 t2
267
268
match1 _ t1@ KSet {} t2@ FunctionApplication {} = addIndeterminate t1 t2
268
269
match1 Rewrite t1@ KSet {} (Var t2) = failWith $ SubjectVariableMatch t1 t2
@@ -626,6 +627,25 @@ containsOtherKeys = \case
626
627
Rest OtherKey {} -> True
627
628
Rest _ -> False
628
629
630
+ ------ Internalised Sets
631
+ matchSets ::
632
+ KSetDefinition ->
633
+ [Term ] ->
634
+ Maybe Term ->
635
+ [Term ] ->
636
+ Maybe Term ->
637
+ StateT MatchState (Except MatchResult ) ()
638
+ matchSets
639
+ def
640
+ patElements
641
+ patRest
642
+ subjElements
643
+ subjRest = do
644
+ -- match only empty sets, indeterminate otherwise
645
+ if null patElements && null subjElements && isNothing patRest && isNothing subjRest
646
+ then pure ()
647
+ else addIndeterminate (KSet def patElements patRest) (KSet def subjElements subjRest)
648
+
629
649
------ Internalised Maps
630
650
matchMaps ::
631
651
KMapDefinition ->
0 commit comments