{-# LANGUAGE QuantifiedConstraints, RankNTypes, UnicodeSyntax, UndecidableInstances #-}
module Data.Equality.Matching.Pattern where
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 = lang (Pattern lang) -> Pattern lang
forall (lang :: * -> *). lang (Pattern lang) -> Pattern lang
NonVariablePattern
instance (∀ a. Eq a => Eq (l a)) => (Eq (Pattern l)) where
== :: Pattern l -> Pattern l -> Bool
(==) (NonVariablePattern l (Pattern l)
a) (NonVariablePattern l (Pattern l)
b) = l (Pattern l) -> l (Pattern l) -> Bool
forall a. Eq a => a -> a -> Bool
(==) l (Pattern l)
a l (Pattern l)
b
(==) (VariablePattern Var
a) (VariablePattern Var
b) = Var
a Var -> Var -> Bool
forall a. Eq a => a -> a -> Bool
== Var
b
(==) Pattern l
_ Pattern l
_ = Bool
False
instance (∀ a. Eq a => Eq (l a), ∀ a. (Ord a) => Ord (l a)) => (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) = Var -> Var -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Var
a Var
b
compare (NonVariablePattern l (Pattern l)
a) (NonVariablePattern l (Pattern l)
b) = l (Pattern l) -> l (Pattern l) -> Ordering
forall a. Ord a => a -> a -> Ordering
compare l (Pattern l)
a l (Pattern l)
b
instance (∀ a. Show a => Show (lang a)) => Show (Pattern lang) where
showsPrec :: Var -> Pattern lang -> ShowS
showsPrec Var
_ (VariablePattern Var
s) = String -> ShowS
showString (Var -> String
forall a. Show a => a -> String
show Var
s)
showsPrec Var
d (NonVariablePattern lang (Pattern lang)
x) = Var -> lang (Pattern lang) -> ShowS
forall a. Show a => Var -> a -> ShowS
showsPrec Var
d lang (Pattern lang)
x
instance IsString (Pattern lang) where
fromString :: String -> Pattern lang
fromString = Var -> Pattern lang
forall (lang :: * -> *). Var -> Pattern lang
VariablePattern (Var -> Pattern lang) -> (String -> Var) -> String -> Pattern lang
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Var
hashString