hegg-0.2.0.0: Fast equality saturation in Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Equality.Matching.Pattern

Description

Definition of Pattern for use in equality matching (Matching), where patterns are matched against the e-graph

Synopsis

Documentation

data Pattern lang Source #

A pattern can be either a variable or an non-variable expression of patterns.

A NonVariablePattern will only match an expression if the lang constructor matches an expression and all child patterns match the expression children. A VariablePattern matches any expression.

Example

The expression

expr :: Fix Sym
expr = BinOp Add (Sym "x") (Const 2.0) -- i.e. x + 2

Would be matched against the following patterns

pat1 :: Pattern Sym
pat1 = VariablePattern 1

pat2 :: Pattern Sym
pat2 = NonVariablePattern (BinOp Add (VariablePattern 1) (VariablePattern 2))

pat3 :: Pattern Sym
pat3 = NonVariablePattern (BinOp Add (VariablePattern 1) (NonVariablePattern (Const 2)))

But would not be matched against the following patterns

pat4 :: Pattern Sym
pat4 = NonVariablePattern (Const 5)

pat5 :: Pattern Sym
pat5 = NonVariablePattern (BinOp Add (NonVariablePattern (Sym "y")) (NonVariablePattern (Const 2)))

pat6 :: Pattern Sym
pat6 = NonVariablePattern (BinOp Add (NonVariablePattern (Sym "x")) (NonVariablePattern (Const 3)))

IsString

Pattern instances IsString, which means one can write a variable pattern simply as a string.

It works by using hashString to create a unique integer for a VariablePattern

For example, we could write the following pattern that would match a+a and b+b but not a+b

pat7 :: Pattern Sym
pat7 = pat (BinOp Add "x" "x")

Constructors

NonVariablePattern (lang (Pattern lang)) 
VariablePattern Var

Should be a >0 positive number

Instances

Instances details
IsString (Pattern lang) Source # 
Instance details

Defined in Data.Equality.Matching.Pattern

Methods

fromString :: String -> Pattern lang #

Show1 lang => Show (Pattern lang) Source # 
Instance details

Defined in Data.Equality.Matching.Pattern

Methods

showsPrec :: Int -> Pattern lang -> ShowS #

show :: Pattern lang -> String #

showList :: [Pattern lang] -> ShowS #

Eq1 l => Eq (Pattern l) Source # 
Instance details

Defined in Data.Equality.Matching.Pattern

Methods

(==) :: Pattern l -> Pattern l -> Bool #

(/=) :: Pattern l -> Pattern l -> Bool #

Ord1 l => Ord (Pattern l) Source # 
Instance details

Defined in Data.Equality.Matching.Pattern

Methods

compare :: Pattern l -> Pattern l -> Ordering #

(<) :: Pattern l -> Pattern l -> Bool #

(<=) :: Pattern l -> Pattern l -> Bool #

(>) :: Pattern l -> Pattern l -> Bool #

(>=) :: Pattern l -> Pattern l -> Bool #

max :: Pattern l -> Pattern l -> Pattern l #

min :: Pattern l -> Pattern l -> Pattern l #

pat :: lang (Pattern lang) -> Pattern lang Source #

Synonym for NonVariablePattern.

Example

pat8 :: Pattern Sym
pat8 = pat (BinOp Mul "y" (pat (Const 2))) -- matches any product of an expression by 2