module Data.Equality.Matching.Pattern where
import Data.Functor.Classes
import Data.String
import Data.Equality.Utils
import Data.Equality.Matching.Database
data Pattern lang
= NonVariablePattern (lang (Pattern lang))
| VariablePattern Var
pat :: lang (Pattern lang) -> Pattern lang
pat :: forall (lang :: * -> *). lang (Pattern lang) -> Pattern lang
pat = forall (lang :: * -> *). lang (Pattern lang) -> Pattern lang
NonVariablePattern
instance Eq1 l => (Eq (Pattern l)) where
== :: Pattern l -> Pattern l -> Bool
(==) (NonVariablePattern l (Pattern l)
a) (NonVariablePattern l (Pattern l)
b) = forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq forall a. Eq a => a -> a -> Bool
(==) l (Pattern l)
a l (Pattern l)
b
(==) (VariablePattern Var
a) (VariablePattern Var
b) = Var
a forall a. Eq a => a -> a -> Bool
== Var
b
(==) Pattern l
_ Pattern l
_ = Bool
False
instance Ord1 l => (Ord (Pattern l)) where
compare :: Pattern l -> Pattern l -> Ordering
compare (VariablePattern Var
_) (NonVariablePattern l (Pattern l)
_) = Ordering
LT
compare (NonVariablePattern l (Pattern l)
_) (VariablePattern Var
_) = Ordering
GT
compare (VariablePattern Var
a) (VariablePattern Var
b) = forall a. Ord a => a -> a -> Ordering
compare Var
a Var
b
compare (NonVariablePattern l (Pattern l)
a) (NonVariablePattern l (Pattern l)
b) = forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare forall a. Ord a => a -> a -> Ordering
compare l (Pattern l)
a l (Pattern l)
b
instance Show1 lang => Show (Pattern lang) where
showsPrec :: Var -> Pattern lang -> ShowS
showsPrec Var
_ (VariablePattern Var
s) = String -> ShowS
showString (forall a. Show a => a -> String
show Var
s)
showsPrec Var
d (NonVariablePattern lang (Pattern lang)
x) = forall (f :: * -> *) a.
Show1 f =>
(Var -> a -> ShowS) -> ([a] -> ShowS) -> Var -> f a -> ShowS
liftShowsPrec forall a. Show a => Var -> a -> ShowS
showsPrec forall a. Show a => [a] -> ShowS
showList Var
d lang (Pattern lang)
x
instance IsString (Pattern lang) where
fromString :: String -> Pattern lang
fromString = forall (lang :: * -> *). Var -> Pattern lang
VariablePattern forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Var
hashString