{-# OPTIONS_GHC -Wno-incomplete-patterns #-} {-# LANGUAGE DerivingStrategies, GeneralizedNewtypeDeriving #-} module Parsley.Internal.Core.Identifiers ( MVar(..), IMVar, ΣVar(..), IΣVar, ) where import Data.Array (Ix) import Data.GADT.Compare (GEq, GCompare, gcompare, geq, GOrdering(..)) import Data.Kind (Type) import Data.Typeable ((:~:)(Refl)) import Data.Word (Word64) import Unsafe.Coerce (unsafeCoerce) newtype ΣVar (a :: Type) = ΣVar IΣVar newtype MVar (a :: Type) = MVar IMVar newtype IMVar = IMVar Word64 deriving newtype (Eq IMVar Eq IMVar -> (IMVar -> IMVar -> Ordering) -> (IMVar -> IMVar -> Bool) -> (IMVar -> IMVar -> Bool) -> (IMVar -> IMVar -> Bool) -> (IMVar -> IMVar -> Bool) -> (IMVar -> IMVar -> IMVar) -> (IMVar -> IMVar -> IMVar) -> Ord IMVar IMVar -> IMVar -> Bool IMVar -> IMVar -> Ordering IMVar -> IMVar -> IMVar 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 min :: IMVar -> IMVar -> IMVar $cmin :: IMVar -> IMVar -> IMVar max :: IMVar -> IMVar -> IMVar $cmax :: IMVar -> IMVar -> IMVar >= :: IMVar -> IMVar -> Bool $c>= :: IMVar -> IMVar -> Bool > :: IMVar -> IMVar -> Bool $c> :: IMVar -> IMVar -> Bool <= :: IMVar -> IMVar -> Bool $c<= :: IMVar -> IMVar -> Bool < :: IMVar -> IMVar -> Bool $c< :: IMVar -> IMVar -> Bool compare :: IMVar -> IMVar -> Ordering $ccompare :: IMVar -> IMVar -> Ordering $cp1Ord :: Eq IMVar Ord, IMVar -> IMVar -> Bool (IMVar -> IMVar -> Bool) -> (IMVar -> IMVar -> Bool) -> Eq IMVar forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: IMVar -> IMVar -> Bool $c/= :: IMVar -> IMVar -> Bool == :: IMVar -> IMVar -> Bool $c== :: IMVar -> IMVar -> Bool Eq, Integer -> IMVar IMVar -> IMVar IMVar -> IMVar -> IMVar (IMVar -> IMVar -> IMVar) -> (IMVar -> IMVar -> IMVar) -> (IMVar -> IMVar -> IMVar) -> (IMVar -> IMVar) -> (IMVar -> IMVar) -> (IMVar -> IMVar) -> (Integer -> IMVar) -> Num IMVar forall a. (a -> a -> a) -> (a -> a -> a) -> (a -> a -> a) -> (a -> a) -> (a -> a) -> (a -> a) -> (Integer -> a) -> Num a fromInteger :: Integer -> IMVar $cfromInteger :: Integer -> IMVar signum :: IMVar -> IMVar $csignum :: IMVar -> IMVar abs :: IMVar -> IMVar $cabs :: IMVar -> IMVar negate :: IMVar -> IMVar $cnegate :: IMVar -> IMVar * :: IMVar -> IMVar -> IMVar $c* :: IMVar -> IMVar -> IMVar - :: IMVar -> IMVar -> IMVar $c- :: IMVar -> IMVar -> IMVar + :: IMVar -> IMVar -> IMVar $c+ :: IMVar -> IMVar -> IMVar Num, Int -> IMVar IMVar -> Int IMVar -> [IMVar] IMVar -> IMVar IMVar -> IMVar -> [IMVar] IMVar -> IMVar -> IMVar -> [IMVar] (IMVar -> IMVar) -> (IMVar -> IMVar) -> (Int -> IMVar) -> (IMVar -> Int) -> (IMVar -> [IMVar]) -> (IMVar -> IMVar -> [IMVar]) -> (IMVar -> IMVar -> [IMVar]) -> (IMVar -> IMVar -> IMVar -> [IMVar]) -> Enum IMVar forall a. (a -> a) -> (a -> a) -> (Int -> a) -> (a -> Int) -> (a -> [a]) -> (a -> a -> [a]) -> (a -> a -> [a]) -> (a -> a -> a -> [a]) -> Enum a enumFromThenTo :: IMVar -> IMVar -> IMVar -> [IMVar] $cenumFromThenTo :: IMVar -> IMVar -> IMVar -> [IMVar] enumFromTo :: IMVar -> IMVar -> [IMVar] $cenumFromTo :: IMVar -> IMVar -> [IMVar] enumFromThen :: IMVar -> IMVar -> [IMVar] $cenumFromThen :: IMVar -> IMVar -> [IMVar] enumFrom :: IMVar -> [IMVar] $cenumFrom :: IMVar -> [IMVar] fromEnum :: IMVar -> Int $cfromEnum :: IMVar -> Int toEnum :: Int -> IMVar $ctoEnum :: Int -> IMVar pred :: IMVar -> IMVar $cpred :: IMVar -> IMVar succ :: IMVar -> IMVar $csucc :: IMVar -> IMVar Enum, Int -> IMVar -> ShowS [IMVar] -> ShowS IMVar -> String (Int -> IMVar -> ShowS) -> (IMVar -> String) -> ([IMVar] -> ShowS) -> Show IMVar forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [IMVar] -> ShowS $cshowList :: [IMVar] -> ShowS show :: IMVar -> String $cshow :: IMVar -> String showsPrec :: Int -> IMVar -> ShowS $cshowsPrec :: Int -> IMVar -> ShowS Show, Ord IMVar Ord IMVar -> ((IMVar, IMVar) -> [IMVar]) -> ((IMVar, IMVar) -> IMVar -> Int) -> ((IMVar, IMVar) -> IMVar -> Int) -> ((IMVar, IMVar) -> IMVar -> Bool) -> ((IMVar, IMVar) -> Int) -> ((IMVar, IMVar) -> Int) -> Ix IMVar (IMVar, IMVar) -> Int (IMVar, IMVar) -> [IMVar] (IMVar, IMVar) -> IMVar -> Bool (IMVar, IMVar) -> IMVar -> Int forall a. Ord a -> ((a, a) -> [a]) -> ((a, a) -> a -> Int) -> ((a, a) -> a -> Int) -> ((a, a) -> a -> Bool) -> ((a, a) -> Int) -> ((a, a) -> Int) -> Ix a unsafeRangeSize :: (IMVar, IMVar) -> Int $cunsafeRangeSize :: (IMVar, IMVar) -> Int rangeSize :: (IMVar, IMVar) -> Int $crangeSize :: (IMVar, IMVar) -> Int inRange :: (IMVar, IMVar) -> IMVar -> Bool $cinRange :: (IMVar, IMVar) -> IMVar -> Bool unsafeIndex :: (IMVar, IMVar) -> IMVar -> Int $cunsafeIndex :: (IMVar, IMVar) -> IMVar -> Int index :: (IMVar, IMVar) -> IMVar -> Int $cindex :: (IMVar, IMVar) -> IMVar -> Int range :: (IMVar, IMVar) -> [IMVar] $crange :: (IMVar, IMVar) -> [IMVar] $cp1Ix :: Ord IMVar Ix) newtype IΣVar = IΣVar Word64 deriving newtype (Eq IΣVar Eq IΣVar -> (IΣVar -> IΣVar -> Ordering) -> (IΣVar -> IΣVar -> Bool) -> (IΣVar -> IΣVar -> Bool) -> (IΣVar -> IΣVar -> Bool) -> (IΣVar -> IΣVar -> Bool) -> (IΣVar -> IΣVar -> IΣVar) -> (IΣVar -> IΣVar -> IΣVar) -> Ord IΣVar IΣVar -> IΣVar -> Bool IΣVar -> IΣVar -> Ordering IΣVar -> IΣVar -> IΣVar 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 min :: IΣVar -> IΣVar -> IΣVar $cmin :: IΣVar -> IΣVar -> IΣVar max :: IΣVar -> IΣVar -> IΣVar $cmax :: IΣVar -> IΣVar -> IΣVar >= :: IΣVar -> IΣVar -> Bool $c>= :: IΣVar -> IΣVar -> Bool > :: IΣVar -> IΣVar -> Bool $c> :: IΣVar -> IΣVar -> Bool <= :: IΣVar -> IΣVar -> Bool $c<= :: IΣVar -> IΣVar -> Bool < :: IΣVar -> IΣVar -> Bool $c< :: IΣVar -> IΣVar -> Bool compare :: IΣVar -> IΣVar -> Ordering $ccompare :: IΣVar -> IΣVar -> Ordering $cp1Ord :: Eq IΣVar Ord, IΣVar -> IΣVar -> Bool (IΣVar -> IΣVar -> Bool) -> (IΣVar -> IΣVar -> Bool) -> Eq IΣVar forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: IΣVar -> IΣVar -> Bool $c/= :: IΣVar -> IΣVar -> Bool == :: IΣVar -> IΣVar -> Bool $c== :: IΣVar -> IΣVar -> Bool Eq, Integer -> IΣVar IΣVar -> IΣVar IΣVar -> IΣVar -> IΣVar (IΣVar -> IΣVar -> IΣVar) -> (IΣVar -> IΣVar -> IΣVar) -> (IΣVar -> IΣVar -> IΣVar) -> (IΣVar -> IΣVar) -> (IΣVar -> IΣVar) -> (IΣVar -> IΣVar) -> (Integer -> IΣVar) -> Num IΣVar forall a. (a -> a -> a) -> (a -> a -> a) -> (a -> a -> a) -> (a -> a) -> (a -> a) -> (a -> a) -> (Integer -> a) -> Num a fromInteger :: Integer -> IΣVar $cfromInteger :: Integer -> IΣVar signum :: IΣVar -> IΣVar $csignum :: IΣVar -> IΣVar abs :: IΣVar -> IΣVar $cabs :: IΣVar -> IΣVar negate :: IΣVar -> IΣVar $cnegate :: IΣVar -> IΣVar * :: IΣVar -> IΣVar -> IΣVar $c* :: IΣVar -> IΣVar -> IΣVar - :: IΣVar -> IΣVar -> IΣVar $c- :: IΣVar -> IΣVar -> IΣVar + :: IΣVar -> IΣVar -> IΣVar $c+ :: IΣVar -> IΣVar -> IΣVar Num, Int -> IΣVar IΣVar -> Int IΣVar -> [IΣVar] IΣVar -> IΣVar IΣVar -> IΣVar -> [IΣVar] IΣVar -> IΣVar -> IΣVar -> [IΣVar] (IΣVar -> IΣVar) -> (IΣVar -> IΣVar) -> (Int -> IΣVar) -> (IΣVar -> Int) -> (IΣVar -> [IΣVar]) -> (IΣVar -> IΣVar -> [IΣVar]) -> (IΣVar -> IΣVar -> [IΣVar]) -> (IΣVar -> IΣVar -> IΣVar -> [IΣVar]) -> Enum IΣVar forall a. (a -> a) -> (a -> a) -> (Int -> a) -> (a -> Int) -> (a -> [a]) -> (a -> a -> [a]) -> (a -> a -> [a]) -> (a -> a -> a -> [a]) -> Enum a enumFromThenTo :: IΣVar -> IΣVar -> IΣVar -> [IΣVar] $cenumFromThenTo :: IΣVar -> IΣVar -> IΣVar -> [IΣVar] enumFromTo :: IΣVar -> IΣVar -> [IΣVar] $cenumFromTo :: IΣVar -> IΣVar -> [IΣVar] enumFromThen :: IΣVar -> IΣVar -> [IΣVar] $cenumFromThen :: IΣVar -> IΣVar -> [IΣVar] enumFrom :: IΣVar -> [IΣVar] $cenumFrom :: IΣVar -> [IΣVar] fromEnum :: IΣVar -> Int $cfromEnum :: IΣVar -> Int toEnum :: Int -> IΣVar $ctoEnum :: Int -> IΣVar pred :: IΣVar -> IΣVar $cpred :: IΣVar -> IΣVar succ :: IΣVar -> IΣVar $csucc :: IΣVar -> IΣVar Enum, Int -> IΣVar -> ShowS [IΣVar] -> ShowS IΣVar -> String (Int -> IΣVar -> ShowS) -> (IΣVar -> String) -> ([IΣVar] -> ShowS) -> Show IΣVar forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [IΣVar] -> ShowS $cshowList :: [IΣVar] -> ShowS show :: IΣVar -> String $cshow :: IΣVar -> String showsPrec :: Int -> IΣVar -> ShowS $cshowsPrec :: Int -> IΣVar -> ShowS Show, Ord IΣVar Ord IΣVar -> ((IΣVar, IΣVar) -> [IΣVar]) -> ((IΣVar, IΣVar) -> IΣVar -> Int) -> ((IΣVar, IΣVar) -> IΣVar -> Int) -> ((IΣVar, IΣVar) -> IΣVar -> Bool) -> ((IΣVar, IΣVar) -> Int) -> ((IΣVar, IΣVar) -> Int) -> Ix IΣVar (IΣVar, IΣVar) -> Int (IΣVar, IΣVar) -> [IΣVar] (IΣVar, IΣVar) -> IΣVar -> Bool (IΣVar, IΣVar) -> IΣVar -> Int forall a. Ord a -> ((a, a) -> [a]) -> ((a, a) -> a -> Int) -> ((a, a) -> a -> Int) -> ((a, a) -> a -> Bool) -> ((a, a) -> Int) -> ((a, a) -> Int) -> Ix a unsafeRangeSize :: (IΣVar, IΣVar) -> Int $cunsafeRangeSize :: (IΣVar, IΣVar) -> Int rangeSize :: (IΣVar, IΣVar) -> Int $crangeSize :: (IΣVar, IΣVar) -> Int inRange :: (IΣVar, IΣVar) -> IΣVar -> Bool $cinRange :: (IΣVar, IΣVar) -> IΣVar -> Bool unsafeIndex :: (IΣVar, IΣVar) -> IΣVar -> Int $cunsafeIndex :: (IΣVar, IΣVar) -> IΣVar -> Int index :: (IΣVar, IΣVar) -> IΣVar -> Int $cindex :: (IΣVar, IΣVar) -> IΣVar -> Int range :: (IΣVar, IΣVar) -> [IΣVar] $crange :: (IΣVar, IΣVar) -> [IΣVar] $cp1Ix :: Ord IΣVar Ix) instance Show (MVar a) where show :: MVar a -> String show (MVar IMVar μ) = String "μ" String -> ShowS forall a. [a] -> [a] -> [a] ++ IMVar -> String forall a. Show a => a -> String show IMVar μ instance Show (ΣVar a) where show :: ΣVar a -> String show (ΣVar IΣVar σ) = String "σ" String -> ShowS forall a. [a] -> [a] -> [a] ++ IΣVar -> String forall a. Show a => a -> String show IΣVar σ instance GEq ΣVar where geq :: ΣVar a -> ΣVar b -> Maybe (a :~: b) geq (ΣVar IΣVar u) (ΣVar IΣVar v) | IΣVar u IΣVar -> IΣVar -> Bool forall a. Eq a => a -> a -> Bool == IΣVar v = (a :~: b) -> Maybe (a :~: b) forall a. a -> Maybe a Just ((Any :~: Any) -> a :~: b forall a b. a -> b unsafeCoerce Any :~: Any forall k (a :: k). a :~: a Refl) | Bool otherwise = Maybe (a :~: b) forall a. Maybe a Nothing instance GCompare ΣVar where gcompare :: ΣVar a -> ΣVar b -> GOrdering a b gcompare σ1 :: ΣVar a σ1@(ΣVar IΣVar u) σ2 :: ΣVar b σ2@(ΣVar IΣVar v) = case IΣVar -> IΣVar -> Ordering forall a. Ord a => a -> a -> Ordering compare IΣVar u IΣVar v of Ordering LT -> GOrdering a b forall k (a :: k) (b :: k). GOrdering a b GLT Ordering EQ -> case ΣVar a -> ΣVar b -> Maybe (a :~: b) forall k (f :: k -> Type) (a :: k) (b :: k). GEq f => f a -> f b -> Maybe (a :~: b) geq ΣVar a σ1 ΣVar b σ2 of Just a :~: b Refl -> GOrdering a b forall k (a :: k). GOrdering a a GEQ Ordering GT -> GOrdering a b forall k (a :: k) (b :: k). GOrdering a b GGT instance GEq MVar where geq :: MVar a -> MVar b -> Maybe (a :~: b) geq (MVar IMVar u) (MVar IMVar v) | IMVar u IMVar -> IMVar -> Bool forall a. Eq a => a -> a -> Bool == IMVar v = (a :~: b) -> Maybe (a :~: b) forall a. a -> Maybe a Just ((Any :~: Any) -> a :~: b forall a b. a -> b unsafeCoerce Any :~: Any forall k (a :: k). a :~: a Refl) | Bool otherwise = Maybe (a :~: b) forall a. Maybe a Nothing instance GCompare MVar where gcompare :: MVar a -> MVar b -> GOrdering a b gcompare μ1 :: MVar a μ1@(MVar IMVar u) μ2 :: MVar b μ2@(MVar IMVar v) = case IMVar -> IMVar -> Ordering forall a. Ord a => a -> a -> Ordering compare IMVar u IMVar v of Ordering LT -> GOrdering a b forall k (a :: k) (b :: k). GOrdering a b GLT Ordering EQ -> case MVar a -> MVar b -> Maybe (a :~: b) forall k (f :: k -> Type) (a :: k) (b :: k). GEq f => f a -> f b -> Maybe (a :~: b) geq MVar a μ1 MVar b μ2 of Just a :~: b Refl -> GOrdering a b forall k (a :: k). GOrdering a a GEQ Ordering GT -> GOrdering a b forall k (a :: k) (b :: k). GOrdering a b GGT