module Unison.Hashing.V2.Pattern ( Pattern (..), SeqOp (..), ) where import Unison.DataDeclaration.ConstructorId (ConstructorId) import Unison.Hashing.V2.Reference (Reference) import Unison.Hashing.V2.Tokenizable qualified as H import Unison.Prelude data Pattern loc = PatternUnbound loc | PatternVar loc | PatternBoolean loc !Bool | PatternInt loc !Int64 | PatternNat loc !Word64 | PatternFloat loc !Double | PatternText loc !Text | PatternChar loc !Char | PatternConstructor loc !Reference !ConstructorId [Pattern loc] | PatternAs loc (Pattern loc) | PatternEffectPure loc (Pattern loc) | PatternEffectBind loc !Reference !ConstructorId [Pattern loc] (Pattern loc) | PatternSequenceLiteral loc [Pattern loc] | PatternSequenceOp loc (Pattern loc) !SeqOp (Pattern loc) deriving stock ((forall m. Monoid m => Pattern m -> m) -> (forall m a. Monoid m => (a -> m) -> Pattern a -> m) -> (forall m a. Monoid m => (a -> m) -> Pattern a -> m) -> (forall a b. (a -> b -> b) -> b -> Pattern a -> b) -> (forall a b. (a -> b -> b) -> b -> Pattern a -> b) -> (forall b a. (b -> a -> b) -> b -> Pattern a -> b) -> (forall b a. (b -> a -> b) -> b -> Pattern a -> b) -> (forall a. (a -> a -> a) -> Pattern a -> a) -> (forall a. (a -> a -> a) -> Pattern a -> a) -> (forall a. Pattern a -> [a]) -> (forall a. Pattern a -> Bool) -> (forall a. Pattern a -> Int) -> (forall a. Eq a => a -> Pattern a -> Bool) -> (forall a. Ord a => Pattern a -> a) -> (forall a. Ord a => Pattern a -> a) -> (forall a. Num a => Pattern a -> a) -> (forall a. Num a => Pattern a -> a) -> Foldable Pattern forall a. Eq a => a -> Pattern a -> Bool forall a. Num a => Pattern a -> a forall a. Ord a => Pattern a -> a forall m. Monoid m => Pattern m -> m forall a. Pattern a -> Bool forall a. Pattern a -> Int forall a. Pattern a -> [a] forall a. (a -> a -> a) -> Pattern a -> a forall m a. Monoid m => (a -> m) -> Pattern a -> m forall b a. (b -> a -> b) -> b -> Pattern a -> b forall a b. (a -> b -> b) -> b -> Pattern a -> b forall (t :: * -> *). (forall m. Monoid m => t m -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall m a. Monoid m => (a -> m) -> t a -> m) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall a b. (a -> b -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall b a. (b -> a -> b) -> b -> t a -> b) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. (a -> a -> a) -> t a -> a) -> (forall a. t a -> [a]) -> (forall a. t a -> Bool) -> (forall a. t a -> Int) -> (forall a. Eq a => a -> t a -> Bool) -> (forall a. Ord a => t a -> a) -> (forall a. Ord a => t a -> a) -> (forall a. Num a => t a -> a) -> (forall a. Num a => t a -> a) -> Foldable t $cfold :: forall m. Monoid m => Pattern m -> m fold :: forall m. Monoid m => Pattern m -> m $cfoldMap :: forall m a. Monoid m => (a -> m) -> Pattern a -> m foldMap :: forall m a. Monoid m => (a -> m) -> Pattern a -> m $cfoldMap' :: forall m a. Monoid m => (a -> m) -> Pattern a -> m foldMap' :: forall m a. Monoid m => (a -> m) -> Pattern a -> m $cfoldr :: forall a b. (a -> b -> b) -> b -> Pattern a -> b foldr :: forall a b. (a -> b -> b) -> b -> Pattern a -> b $cfoldr' :: forall a b. (a -> b -> b) -> b -> Pattern a -> b foldr' :: forall a b. (a -> b -> b) -> b -> Pattern a -> b $cfoldl :: forall b a. (b -> a -> b) -> b -> Pattern a -> b foldl :: forall b a. (b -> a -> b) -> b -> Pattern a -> b $cfoldl' :: forall b a. (b -> a -> b) -> b -> Pattern a -> b foldl' :: forall b a. (b -> a -> b) -> b -> Pattern a -> b $cfoldr1 :: forall a. (a -> a -> a) -> Pattern a -> a foldr1 :: forall a. (a -> a -> a) -> Pattern a -> a $cfoldl1 :: forall a. (a -> a -> a) -> Pattern a -> a foldl1 :: forall a. (a -> a -> a) -> Pattern a -> a $ctoList :: forall a. Pattern a -> [a] toList :: forall a. Pattern a -> [a] $cnull :: forall a. Pattern a -> Bool null :: forall a. Pattern a -> Bool $clength :: forall a. Pattern a -> Int length :: forall a. Pattern a -> Int $celem :: forall a. Eq a => a -> Pattern a -> Bool elem :: forall a. Eq a => a -> Pattern a -> Bool $cmaximum :: forall a. Ord a => Pattern a -> a maximum :: forall a. Ord a => Pattern a -> a $cminimum :: forall a. Ord a => Pattern a -> a minimum :: forall a. Ord a => Pattern a -> a $csum :: forall a. Num a => Pattern a -> a sum :: forall a. Num a => Pattern a -> a $cproduct :: forall a. Num a => Pattern a -> a product :: forall a. Num a => Pattern a -> a Foldable, (forall a b. (a -> b) -> Pattern a -> Pattern b) -> (forall a b. a -> Pattern b -> Pattern a) -> Functor Pattern forall a b. a -> Pattern b -> Pattern a forall a b. (a -> b) -> Pattern a -> Pattern b forall (f :: * -> *). (forall a b. (a -> b) -> f a -> f b) -> (forall a b. a -> f b -> f a) -> Functor f $cfmap :: forall a b. (a -> b) -> Pattern a -> Pattern b fmap :: forall a b. (a -> b) -> Pattern a -> Pattern b $c<$ :: forall a b. a -> Pattern b -> Pattern a <$ :: forall a b. a -> Pattern b -> Pattern a Functor, (forall x. Pattern loc -> Rep (Pattern loc) x) -> (forall x. Rep (Pattern loc) x -> Pattern loc) -> Generic (Pattern loc) forall x. Rep (Pattern loc) x -> Pattern loc forall x. Pattern loc -> Rep (Pattern loc) x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a forall loc x. Rep (Pattern loc) x -> Pattern loc forall loc x. Pattern loc -> Rep (Pattern loc) x $cfrom :: forall loc x. Pattern loc -> Rep (Pattern loc) x from :: forall x. Pattern loc -> Rep (Pattern loc) x $cto :: forall loc x. Rep (Pattern loc) x -> Pattern loc to :: forall x. Rep (Pattern loc) x -> Pattern loc Generic, Eq (Pattern loc) Eq (Pattern loc) => (Pattern loc -> Pattern loc -> Ordering) -> (Pattern loc -> Pattern loc -> Bool) -> (Pattern loc -> Pattern loc -> Bool) -> (Pattern loc -> Pattern loc -> Bool) -> (Pattern loc -> Pattern loc -> Bool) -> (Pattern loc -> Pattern loc -> Pattern loc) -> (Pattern loc -> Pattern loc -> Pattern loc) -> Ord (Pattern loc) Pattern loc -> Pattern loc -> Bool Pattern loc -> Pattern loc -> Ordering Pattern loc -> Pattern loc -> Pattern loc forall a. Eq a => (a -> a -> Ordering) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> a) -> (a -> a -> a) -> Ord a forall loc. Ord loc => Eq (Pattern loc) forall loc. Ord loc => Pattern loc -> Pattern loc -> Bool forall loc. Ord loc => Pattern loc -> Pattern loc -> Ordering forall loc. Ord loc => Pattern loc -> Pattern loc -> Pattern loc $ccompare :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Ordering compare :: Pattern loc -> Pattern loc -> Ordering $c< :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Bool < :: Pattern loc -> Pattern loc -> Bool $c<= :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Bool <= :: Pattern loc -> Pattern loc -> Bool $c> :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Bool > :: Pattern loc -> Pattern loc -> Bool $c>= :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Bool >= :: Pattern loc -> Pattern loc -> Bool $cmax :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Pattern loc max :: Pattern loc -> Pattern loc -> Pattern loc $cmin :: forall loc. Ord loc => Pattern loc -> Pattern loc -> Pattern loc min :: Pattern loc -> Pattern loc -> Pattern loc Ord, Int -> Pattern loc -> ShowS [Pattern loc] -> ShowS Pattern loc -> String (Int -> Pattern loc -> ShowS) -> (Pattern loc -> String) -> ([Pattern loc] -> ShowS) -> Show (Pattern loc) forall loc. Show loc => Int -> Pattern loc -> ShowS forall loc. Show loc => [Pattern loc] -> ShowS forall loc. Show loc => Pattern loc -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: forall loc. Show loc => Int -> Pattern loc -> ShowS showsPrec :: Int -> Pattern loc -> ShowS $cshow :: forall loc. Show loc => Pattern loc -> String show :: Pattern loc -> String $cshowList :: forall loc. Show loc => [Pattern loc] -> ShowS showList :: [Pattern loc] -> ShowS Show, Functor Pattern Foldable Pattern (Functor Pattern, Foldable Pattern) => (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> Pattern a -> f (Pattern b)) -> (forall (f :: * -> *) a. Applicative f => Pattern (f a) -> f (Pattern a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> Pattern a -> m (Pattern b)) -> (forall (m :: * -> *) a. Monad m => Pattern (m a) -> m (Pattern a)) -> Traversable Pattern forall (t :: * -> *). (Functor t, Foldable t) => (forall (f :: * -> *) a b. Applicative f => (a -> f b) -> t a -> f (t b)) -> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a)) -> (forall (m :: * -> *) a b. Monad m => (a -> m b) -> t a -> m (t b)) -> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a)) -> Traversable t forall (m :: * -> *) a. Monad m => Pattern (m a) -> m (Pattern a) forall (f :: * -> *) a. Applicative f => Pattern (f a) -> f (Pattern a) forall (m :: * -> *) a b. Monad m => (a -> m b) -> Pattern a -> m (Pattern b) forall (f :: * -> *) a b. Applicative f => (a -> f b) -> Pattern a -> f (Pattern b) $ctraverse :: forall (f :: * -> *) a b. Applicative f => (a -> f b) -> Pattern a -> f (Pattern b) traverse :: forall (f :: * -> *) a b. Applicative f => (a -> f b) -> Pattern a -> f (Pattern b) $csequenceA :: forall (f :: * -> *) a. Applicative f => Pattern (f a) -> f (Pattern a) sequenceA :: forall (f :: * -> *) a. Applicative f => Pattern (f a) -> f (Pattern a) $cmapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> Pattern a -> m (Pattern b) mapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> Pattern a -> m (Pattern b) $csequence :: forall (m :: * -> *) a. Monad m => Pattern (m a) -> m (Pattern a) sequence :: forall (m :: * -> *) a. Monad m => Pattern (m a) -> m (Pattern a) Traversable) data SeqOp = Cons | Snoc | Concat deriving (SeqOp -> SeqOp -> Bool (SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> Bool) -> Eq SeqOp forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: SeqOp -> SeqOp -> Bool == :: SeqOp -> SeqOp -> Bool $c/= :: SeqOp -> SeqOp -> Bool /= :: SeqOp -> SeqOp -> Bool Eq, Int -> SeqOp -> ShowS [SeqOp] -> ShowS SeqOp -> String (Int -> SeqOp -> ShowS) -> (SeqOp -> String) -> ([SeqOp] -> ShowS) -> Show SeqOp forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> SeqOp -> ShowS showsPrec :: Int -> SeqOp -> ShowS $cshow :: SeqOp -> String show :: SeqOp -> String $cshowList :: [SeqOp] -> ShowS showList :: [SeqOp] -> ShowS Show, Eq SeqOp Eq SeqOp => (SeqOp -> SeqOp -> Ordering) -> (SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> Bool) -> (SeqOp -> SeqOp -> SeqOp) -> (SeqOp -> SeqOp -> SeqOp) -> Ord SeqOp SeqOp -> SeqOp -> Bool SeqOp -> SeqOp -> Ordering SeqOp -> SeqOp -> SeqOp forall a. Eq a => (a -> a -> Ordering) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> a) -> (a -> a -> a) -> Ord a $ccompare :: SeqOp -> SeqOp -> Ordering compare :: SeqOp -> SeqOp -> Ordering $c< :: SeqOp -> SeqOp -> Bool < :: SeqOp -> SeqOp -> Bool $c<= :: SeqOp -> SeqOp -> Bool <= :: SeqOp -> SeqOp -> Bool $c> :: SeqOp -> SeqOp -> Bool > :: SeqOp -> SeqOp -> Bool $c>= :: SeqOp -> SeqOp -> Bool >= :: SeqOp -> SeqOp -> Bool $cmax :: SeqOp -> SeqOp -> SeqOp max :: SeqOp -> SeqOp -> SeqOp $cmin :: SeqOp -> SeqOp -> SeqOp min :: SeqOp -> SeqOp -> SeqOp Ord, (forall x. SeqOp -> Rep SeqOp x) -> (forall x. Rep SeqOp x -> SeqOp) -> Generic SeqOp forall x. Rep SeqOp x -> SeqOp forall x. SeqOp -> Rep SeqOp x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. SeqOp -> Rep SeqOp x from :: forall x. SeqOp -> Rep SeqOp x $cto :: forall x. Rep SeqOp x -> SeqOp to :: forall x. Rep SeqOp x -> SeqOp Generic) instance H.Tokenizable SeqOp where tokens :: SeqOp -> [Token] tokens SeqOp Cons = [Word8 -> Token H.Tag Word8 0] tokens SeqOp Snoc = [Word8 -> Token H.Tag Word8 1] tokens SeqOp Concat = [Word8 -> Token H.Tag Word8 2] instance H.Tokenizable (Pattern p) where tokens :: Pattern p -> [Token] tokens (PatternUnbound p _) = [Word8 -> Token H.Tag Word8 0] tokens (PatternVar p _) = [Word8 -> Token H.Tag Word8 1] tokens (PatternBoolean p _ Bool b) = Word8 -> Token H.Tag Word8 2 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : [Word8 -> Token H.Tag (Word8 -> Token) -> Word8 -> Token forall a b. (a -> b) -> a -> b $ if Bool b then Word8 1 else Word8 0] tokens (PatternInt p _ Int64 n) = Word8 -> Token H.Tag Word8 3 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : [Int64 -> Token H.Int Int64 n] tokens (PatternNat p _ Word64 n) = Word8 -> Token H.Tag Word8 4 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : [Word64 -> Token H.Nat Word64 n] tokens (PatternFloat p _ Double f) = Word8 -> Token H.Tag Word8 5 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : Double -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Double f tokens (PatternConstructor p _ Reference r Word64 n [Pattern p] args) = [Word8 -> Token H.Tag Word8 6, Reference -> Token forall t. Tokenizable t => t -> Token H.accumulateToken Reference r, Word64 -> Token H.Nat (Word64 -> Token) -> Word64 -> Token forall a b. (a -> b) -> a -> b $ Word64 -> Word64 forall a b. (Integral a, Num b) => a -> b fromIntegral Word64 n, [Pattern p] -> Token forall t. Tokenizable t => t -> Token H.accumulateToken [Pattern p] args] tokens (PatternEffectPure p _ Pattern p p) = Word8 -> Token H.Tag Word8 7 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : Pattern p -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Pattern p p tokens (PatternEffectBind p _ Reference r Word64 n [Pattern p] args Pattern p k) = [Word8 -> Token H.Tag Word8 8, Reference -> Token forall t. Tokenizable t => t -> Token H.accumulateToken Reference r, Word64 -> Token H.Nat (Word64 -> Token) -> Word64 -> Token forall a b. (a -> b) -> a -> b $ Word64 -> Word64 forall a b. (Integral a, Num b) => a -> b fromIntegral Word64 n, [Pattern p] -> Token forall t. Tokenizable t => t -> Token H.accumulateToken [Pattern p] args, Pattern p -> Token forall t. Tokenizable t => t -> Token H.accumulateToken Pattern p k] tokens (PatternAs p _ Pattern p p) = Word8 -> Token H.Tag Word8 9 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : Pattern p -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Pattern p p tokens (PatternText p _ Text t) = Word8 -> Token H.Tag Word8 10 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : Text -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Text t tokens (PatternSequenceLiteral p _ [Pattern p] ps) = Word8 -> Token H.Tag Word8 11 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : (Pattern p -> [Token]) -> [Pattern p] -> [Token] forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b] concatMap Pattern p -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens [Pattern p] ps tokens (PatternSequenceOp p _ Pattern p l SeqOp op Pattern p r) = Word8 -> Token H.Tag Word8 12 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : SeqOp -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens SeqOp op [Token] -> [Token] -> [Token] forall a. [a] -> [a] -> [a] ++ Pattern p -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Pattern p l [Token] -> [Token] -> [Token] forall a. [a] -> [a] -> [a] ++ Pattern p -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Pattern p r tokens (PatternChar p _ Char c) = Word8 -> Token H.Tag Word8 13 Token -> [Token] -> [Token] forall a. a -> [a] -> [a] : Char -> [Token] forall t. Tokenizable t => t -> [Token] H.tokens Char c instance Eq (Pattern loc) where PatternUnbound loc _ == :: Pattern loc -> Pattern loc -> Bool == PatternUnbound loc _ = Bool True PatternVar loc _ == PatternVar loc _ = Bool True PatternBoolean loc _ Bool b == PatternBoolean loc _ Bool b2 = Bool b Bool -> Bool -> Bool forall a. Eq a => a -> a -> Bool == Bool b2 PatternInt loc _ Int64 n == PatternInt loc _ Int64 m = Int64 n Int64 -> Int64 -> Bool forall a. Eq a => a -> a -> Bool == Int64 m PatternNat loc _ Word64 n == PatternNat loc _ Word64 m = Word64 n Word64 -> Word64 -> Bool forall a. Eq a => a -> a -> Bool == Word64 m PatternFloat loc _ Double f == PatternFloat loc _ Double g = Double f Double -> Double -> Bool forall a. Eq a => a -> a -> Bool == Double g PatternConstructor loc _ Reference r Word64 n [Pattern loc] args == PatternConstructor loc _ Reference s Word64 m [Pattern loc] brgs = Reference r Reference -> Reference -> Bool forall a. Eq a => a -> a -> Bool == Reference s Bool -> Bool -> Bool && Word64 n Word64 -> Word64 -> Bool forall a. Eq a => a -> a -> Bool == Word64 m Bool -> Bool -> Bool && [Pattern loc] args [Pattern loc] -> [Pattern loc] -> Bool forall a. Eq a => a -> a -> Bool == [Pattern loc] brgs PatternEffectPure loc _ Pattern loc p == PatternEffectPure loc _ Pattern loc q = Pattern loc p Pattern loc -> Pattern loc -> Bool forall a. Eq a => a -> a -> Bool == Pattern loc q PatternEffectBind loc _ Reference r Word64 ctor [Pattern loc] ps Pattern loc k == PatternEffectBind loc _ Reference r2 Word64 ctor2 [Pattern loc] ps2 Pattern loc k2 = Reference r Reference -> Reference -> Bool forall a. Eq a => a -> a -> Bool == Reference r2 Bool -> Bool -> Bool && Word64 ctor Word64 -> Word64 -> Bool forall a. Eq a => a -> a -> Bool == Word64 ctor2 Bool -> Bool -> Bool && [Pattern loc] ps [Pattern loc] -> [Pattern loc] -> Bool forall a. Eq a => a -> a -> Bool == [Pattern loc] ps2 Bool -> Bool -> Bool && Pattern loc k Pattern loc -> Pattern loc -> Bool forall a. Eq a => a -> a -> Bool == Pattern loc k2 PatternAs loc _ Pattern loc p == PatternAs loc _ Pattern loc q = Pattern loc p Pattern loc -> Pattern loc -> Bool forall a. Eq a => a -> a -> Bool == Pattern loc q PatternText loc _ Text t == PatternText loc _ Text t2 = Text t Text -> Text -> Bool forall a. Eq a => a -> a -> Bool == Text t2 PatternSequenceLiteral loc _ [Pattern loc] ps == PatternSequenceLiteral loc _ [Pattern loc] ps2 = [Pattern loc] ps [Pattern loc] -> [Pattern loc] -> Bool forall a. Eq a => a -> a -> Bool == [Pattern loc] ps2 PatternSequenceOp loc _ Pattern loc ph SeqOp op Pattern loc pt == PatternSequenceOp loc _ Pattern loc ph2 SeqOp op2 Pattern loc pt2 = Pattern loc ph Pattern loc -> Pattern loc -> Bool forall a. Eq a => a -> a -> Bool == Pattern loc ph2 Bool -> Bool -> Bool && SeqOp op SeqOp -> SeqOp -> Bool forall a. Eq a => a -> a -> Bool == SeqOp op2 Bool -> Bool -> Bool && Pattern loc pt Pattern loc -> Pattern loc -> Bool forall a. Eq a => a -> a -> Bool == Pattern loc pt2 Pattern loc _ == Pattern loc _ = Bool False