{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
module Pinch.Internal.TType
(
TType(..)
, IsTType(..)
, SomeTType(..)
, ttypeEquality
, ttypeEqT
, TBool
, TByte
, TDouble
, TInt16
, TInt32
, TEnum
, TInt64
, TBinary
, TText
, TStruct
, TUnion
, TException
, TMap
, TSet
, TList
) where
import Data.Hashable (Hashable (..))
import Data.Typeable ((:~:) (..), Typeable)
data TBool deriving (Typeable)
data TByte deriving (Typeable)
data TDouble deriving (Typeable)
data TInt16 deriving (Typeable)
data TInt32 deriving (Typeable)
type TEnum = TInt32
data TInt64 deriving (Typeable)
data TBinary deriving (Typeable)
type TText = TBinary
data TStruct deriving (Typeable)
type TUnion = TStruct
type TException = TStruct
data TMap deriving (Typeable)
data TSet deriving (Typeable)
data TList deriving (Typeable)
data TType a where
TBool :: TType TBool
TByte :: TType TByte
TDouble :: TType TDouble
TInt16 :: TType TInt16
TInt32 :: TType TInt32
TInt64 :: TType TInt64
TBinary :: TType TBinary
TStruct :: TType TStruct
TMap :: TType TMap
TSet :: TType TSet
TList :: TType TList
deriving (Typeable)
deriving instance Show (TType a)
deriving instance Eq (TType a)
instance Hashable (TType a) where
hashWithSalt :: Int -> TType a -> Int
hashWithSalt Int
s TType a
TBool = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
0 :: Int)
hashWithSalt Int
s TType a
TByte = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
1 :: Int)
hashWithSalt Int
s TType a
TDouble = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
2 :: Int)
hashWithSalt Int
s TType a
TInt16 = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
3 :: Int)
hashWithSalt Int
s TType a
TInt32 = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
4 :: Int)
hashWithSalt Int
s TType a
TInt64 = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
5 :: Int)
hashWithSalt Int
s TType a
TBinary = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
6 :: Int)
hashWithSalt Int
s TType a
TStruct = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
7 :: Int)
hashWithSalt Int
s TType a
TMap = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
8 :: Int)
hashWithSalt Int
s TType a
TSet = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
9 :: Int)
hashWithSalt Int
s TType a
TList = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
10 :: Int)
class Typeable a => IsTType a where
ttype :: TType a
instance IsTType TBool where ttype :: TType TBool
ttype = TType TBool
TBool
instance IsTType TByte where ttype :: TType TByte
ttype = TType TByte
TByte
instance IsTType TDouble where ttype :: TType TDouble
ttype = TType TDouble
TDouble
instance IsTType TInt16 where ttype :: TType TInt16
ttype = TType TInt16
TInt16
instance IsTType TInt32 where ttype :: TType TInt32
ttype = TType TInt32
TInt32
instance IsTType TInt64 where ttype :: TType TInt64
ttype = TType TInt64
TInt64
instance IsTType TBinary where ttype :: TType TBinary
ttype = TType TBinary
TBinary
instance IsTType TStruct where ttype :: TType TStruct
ttype = TType TStruct
TStruct
instance IsTType TMap where ttype :: TType TMap
ttype = TType TMap
TMap
instance IsTType TSet where ttype :: TType TSet
ttype = TType TSet
TSet
instance IsTType TList where ttype :: TType TList
ttype = TType TList
TList
data SomeTType where
SomeTType :: forall a. IsTType a => TType a -> SomeTType
deriving Typeable
deriving instance Show SomeTType
ttypeEquality :: TType a -> TType b -> Maybe (a :~: b)
ttypeEquality :: TType a -> TType b -> Maybe (a :~: b)
ttypeEquality TType a
TBool TType b
TBool = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TByte TType b
TByte = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TDouble TType b
TDouble = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TInt16 TType b
TInt16 = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TInt32 TType b
TInt32 = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TInt64 TType b
TInt64 = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TBinary TType b
TBinary = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TStruct TType b
TStruct = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TMap TType b
TMap = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TSet TType b
TSet = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
TList TType b
TList = (a :~: a) -> Maybe (a :~: a)
forall a. a -> Maybe a
Just a :~: a
forall k (a :: k). a :~: a
Refl
ttypeEquality TType a
_ TType b
_ = Maybe (a :~: b)
forall a. Maybe a
Nothing
{-# INLINE ttypeEquality #-}
ttypeEqT :: forall a b. (IsTType a, IsTType b) => Maybe (a :~: b)
ttypeEqT :: Maybe (a :~: b)
ttypeEqT = TType a -> TType b -> Maybe (a :~: b)
forall a b. TType a -> TType b -> Maybe (a :~: b)
ttypeEquality TType a
forall a. IsTType a => TType a
ttype TType b
forall a. IsTType a => TType a
ttype
{-# INLINE ttypeEqT #-}