@@ -596,17 +596,20 @@ pattern KMap def keyVals rest <- Term _ (KMapF def keyVals rest)
596
596
r -> ([] , r)
597
597
newKeyVals = sortAndDeduplicate $ keyVals ++ keyVals'
598
598
newRest = rest'
599
- in Term
600
- argAttributes
601
- { hash =
602
- Hashable. hash
603
- ( " KMap" :: ByteString
604
- , def
605
- , map (\ (k, v) -> (hash $ getAttributes k, hash $ getAttributes v)) newKeyVals
606
- , hash . getAttributes <$> newRest
607
- )
608
- }
609
- $ KMapF def newKeyVals newRest
599
+ in case (newKeyVals, newRest) of
600
+ ([] , Just r) -> r
601
+ _ ->
602
+ Term
603
+ argAttributes
604
+ { hash =
605
+ Hashable. hash
606
+ ( " KMap" :: ByteString
607
+ , def
608
+ , map (\ (k, v) -> (hash $ getAttributes k, hash $ getAttributes v)) newKeyVals
609
+ , hash . getAttributes <$> newRest
610
+ )
611
+ }
612
+ $ KMapF def newKeyVals newRest
610
613
611
614
pattern KList :: KListDefinition -> [Term ] -> Maybe (Term , [Term ]) -> Term
612
615
pattern KList def heads rest <- Term _ (KListF def heads rest)
@@ -630,18 +633,21 @@ pattern KList def heads rest <- Term _ (KListF def heads rest)
630
633
(\ (m, ts) -> (heads <> heads', Just (m, ts <> tails)))
631
634
rest'
632
635
other -> (heads, other)
633
- in Term
634
- argAttributes
635
- { hash =
636
- Hashable. hash
637
- ( " KList" :: ByteString
638
- , def
639
- , map (hash . getAttributes) newHeads
640
- , fmap (hash . getAttributes . fst ) newRest
641
- , fmap (map (hash . getAttributes) . snd ) newRest
642
- )
643
- }
644
- $ KListF def newHeads newRest
636
+ in case (newHeads, newRest) of
637
+ ([] , Just (r, [] )) -> r
638
+ _ ->
639
+ Term
640
+ argAttributes
641
+ { hash =
642
+ Hashable. hash
643
+ ( " KList" :: ByteString
644
+ , def
645
+ , map (hash . getAttributes) newHeads
646
+ , fmap (hash . getAttributes . fst ) newRest
647
+ , fmap (map (hash . getAttributes) . snd ) newRest
648
+ )
649
+ }
650
+ $ KListF def newHeads newRest
645
651
646
652
pattern KSet :: KSetDefinition -> [Term ] -> Maybe Term -> Term
647
653
pattern KSet def elements rest <- Term _ (KSetF def elements rest)
@@ -662,17 +668,20 @@ pattern KSet def elements rest <- Term _ (KSetF def elements rest)
662
668
other -> ([] , other)
663
669
newElements = sortAndDeduplicate $ elements <> elements'
664
670
newRest = rest'
665
- in Term
666
- argAttributes
667
- { hash =
668
- Hashable. hash
669
- ( " KSet" :: ByteString
670
- , def
671
- , map (hash . getAttributes) newElements
672
- , fmap (hash . getAttributes) newRest
673
- )
674
- }
675
- $ KSetF def newElements newRest
671
+ in case (newElements, newRest) of
672
+ ([] , Just r) -> r
673
+ _ ->
674
+ Term
675
+ argAttributes
676
+ { hash =
677
+ Hashable. hash
678
+ ( " KSet" :: ByteString
679
+ , def
680
+ , map (hash . getAttributes) newElements
681
+ , fmap (hash . getAttributes) newRest
682
+ )
683
+ }
684
+ $ KSetF def newElements newRest
676
685
{-# COMPLETE AndTerm, SymbolApplication, DomainValue, Var, Injection, KMap, KList, KSet #-}
677
686
678
687
-- hard-wired injection symbol
0 commit comments