@@ -14,25 +14,28 @@ Portability : portable
1414module Kore.Internal.MultiAnd
1515 ( MultiAnd
1616 , top
17- , extractPatterns
1817 , make
1918 , toPredicate
2019 , fromPredicate
2120 , fromTermLike
2221 , singleton
2322 , toPattern
2423 , map
24+ , traverse
2525 ) where
2626
2727import Prelude.Kore hiding
2828 ( map
29+ , traverse
2930 )
3031
3132import Control.DeepSeq
3233 ( NFData
3334 )
35+ import qualified Data.Foldable as Foldable
3436import qualified Data.Functor.Foldable as Recursive
3537import qualified Data.Set as Set
38+ import qualified Data.Traversable as Traversable
3639import qualified Generics.SOP as SOP
3740import qualified GHC.Exts as GHC
3841import qualified GHC.Generics as GHC
@@ -72,9 +75,7 @@ A non-empty 'MultiAnd' would also have a nice symmetry between 'Top' and
7275-}
7376newtype MultiAnd child = MultiAnd { getMultiAnd :: [child ] }
7477 deriving (Eq , Ord , Show )
75- deriving (Semigroup , Monoid )
76- deriving (Functor , Applicative , Monad , Alternative )
77- deriving (Foldable , Traversable )
78+ deriving (Foldable )
7879 deriving (GHC.Generic , GHC.IsList )
7980
8081instance SOP. Generic (MultiAnd child )
@@ -95,6 +96,14 @@ instance Debug child => Debug (MultiAnd child)
9596
9697instance (Debug child , Diff child ) => Diff (MultiAnd child )
9798
99+ instance (Ord child , TopBottom child ) => Semigroup (MultiAnd child ) where
100+ (MultiAnd [] ) <> b = b
101+ a <> (MultiAnd [] ) = a
102+ (MultiAnd a) <> (MultiAnd b) = make (a <> b)
103+
104+ instance (Ord child , TopBottom child ) => Monoid (MultiAnd child ) where
105+ mempty = make []
106+
98107instance
99108 InternalVariable variable
100109 => From (MultiAnd (Predicate variable )) (Predicate variable )
@@ -148,12 +157,6 @@ make patts = filterAnd (MultiAnd patts)
148157singleton :: (Ord term , TopBottom term ) => term -> MultiAnd term
149158singleton term = make [term]
150159
151- {-| Returns the patterns inside an @\and@.
152- -}
153- extractPatterns :: MultiAnd term -> [term ]
154- extractPatterns = getMultiAnd
155-
156-
157160{- | Simplify the conjunction.
158161
159162The arguments are simplified by filtering on @\\top@ and @\\bottom@. The
245248 => (child1 -> child2 )
246249 -> MultiAnd child1
247250 -> MultiAnd child2
248- map f = make . fmap f . extractPatterns
251+ map f = make . fmap f . Foldable. toList
252+ {-# INLINE map #-}
253+
254+ traverse
255+ :: Ord child2
256+ => TopBottom child2
257+ => Applicative f
258+ => (child1 -> f child2 )
259+ -> MultiAnd child1
260+ -> f (MultiAnd child2 )
261+ traverse f = fmap make . Traversable. traverse f . Foldable. toList
262+ {-# INLINE traverse #-}
0 commit comments