{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE RoleAnnotations #-}
module GHC.Internal.TypeLits
(
N.Natural, N.Nat, Symbol
, N.KnownNat(natSing), natVal, natVal'
, KnownSymbol(symbolSing), symbolVal, symbolVal'
, KnownChar(charSing), charVal, charVal'
, N.SomeNat(..), SomeSymbol(..), SomeChar(..)
, someNatVal, someSymbolVal, someCharVal
, N.sameNat, sameSymbol, sameChar
, N.decideNat, decideSymbol, decideChar
, OrderingI(..)
, N.cmpNat, cmpSymbol, cmpChar
, N.SNat, SSymbol, SChar
, pattern N.SNat, pattern SSymbol, pattern SChar
, fromSNat, fromSSymbol, fromSChar
, withSomeSNat, withSomeSSymbol, withSomeSChar
, N.withKnownNat, withKnownSymbol, withKnownChar
, type (N.<=), type (N.<=?), type (N.+), type (N.*), type (N.^), type (N.-)
, type N.Div, type N.Mod, type N.Log2
, AppendSymbol
, N.CmpNat, CmpSymbol, CmpChar
, ConsSymbol, UnconsSymbol
, CharToNat, NatToChar
, TypeError
, ErrorMessage(..)
) where
import GHC.Internal.Base ( Bool(..), Eq(..), Functor(..), Ord(..), Ordering(..), String
, (.), otherwise, withDict, Void, (++)
, errorWithoutStackTrace)
import GHC.Types(Symbol, Char, TYPE)
import GHC.Internal.TypeError(ErrorMessage(..), TypeError)
import GHC.Internal.Num(Integer, fromInteger)
import GHC.Internal.Show(Show(..), appPrec, appPrec1, showParen, showString)
import GHC.Internal.Read(Read(..))
import GHC.Internal.Real(toInteger)
import GHC.Prim(Proxy#)
import GHC.Internal.Data.Either (Either (..))
import GHC.Internal.Data.Maybe (Maybe(..))
import GHC.Internal.Data.Proxy (Proxy(..))
import GHC.Internal.Data.Type.Coercion (Coercion(..), TestCoercion(..))
import GHC.Internal.Data.Type.Equality((:~:)(Refl), TestEquality(..))
import GHC.Internal.Data.Type.Ord(OrderingI(..))
import GHC.Internal.Unsafe.Coerce(unsafeCoerce)
import GHC.Internal.TypeLits.Internal(CmpSymbol, CmpChar)
import qualified GHC.Internal.TypeNats as N
class KnownSymbol (n :: Symbol) where
symbolSing :: SSymbol n
natVal :: forall n proxy. N.KnownNat n => proxy n -> Integer
natVal :: forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Integer
natVal proxy n
p = Natural -> Integer
forall a. Integral a => a -> Integer
toInteger (proxy n -> Natural
forall (n :: Natural) (proxy :: Natural -> *).
KnownNat n =>
proxy n -> Natural
N.natVal proxy n
p)
symbolVal :: forall n proxy. KnownSymbol n => proxy n -> String
symbolVal :: forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal proxy n
_ = case SSymbol n
forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing :: SSymbol n of
UnsafeSSymbol String
x -> String
x
natVal' :: forall n. N.KnownNat n => Proxy# n -> Integer
natVal' :: forall (n :: Natural). KnownNat n => Proxy# n -> Integer
natVal' Proxy# n
p = Natural -> Integer
forall a. Integral a => a -> Integer
toInteger (Proxy# n -> Natural
forall (n :: Natural). KnownNat n => Proxy# n -> Natural
N.natVal' Proxy# n
p)
symbolVal' :: forall n. KnownSymbol n => Proxy# n -> String
symbolVal' :: forall (n :: Symbol). KnownSymbol n => Proxy# n -> String
symbolVal' Proxy# n
_ = case SSymbol n
forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing :: SSymbol n of
UnsafeSSymbol String
x -> String
x
data SomeSymbol = forall n. KnownSymbol n => SomeSymbol (Proxy n)
class KnownChar (n :: Char) where
charSing :: SChar n
charVal :: forall n proxy. KnownChar n => proxy n -> Char
charVal :: forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal proxy n
_ = case SChar n
forall (n :: Char). KnownChar n => SChar n
charSing :: SChar n of
UnsafeSChar Char
x -> Char
x
charVal' :: forall n. KnownChar n => Proxy# n -> Char
charVal' :: forall (n :: Char). KnownChar n => Proxy# n -> Char
charVal' Proxy# n
_ = case SChar n
forall (n :: Char). KnownChar n => SChar n
charSing :: SChar n of
UnsafeSChar Char
x -> Char
x
data SomeChar = forall n. KnownChar n => SomeChar (Proxy n)
someNatVal :: Integer -> Maybe N.SomeNat
someNatVal :: Integer -> Maybe SomeNat
someNatVal Integer
n
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0 = SomeNat -> Maybe SomeNat
forall a. a -> Maybe a
Just (Natural -> SomeNat
N.someNatVal (Integer -> Natural
forall a. Num a => Integer -> a
fromInteger Integer
n))
| Bool
otherwise = Maybe SomeNat
forall a. Maybe a
Nothing
someSymbolVal :: String -> SomeSymbol
someSymbolVal :: String -> SomeSymbol
someSymbolVal String
s = String
-> (forall (s :: Symbol). SSymbol s -> SomeSymbol) -> SomeSymbol
forall r. String -> (forall (s :: Symbol). SSymbol s -> r) -> r
withSomeSSymbol String
s (\(SSymbol s
ss :: SSymbol s) ->
SSymbol s -> (KnownSymbol s => SomeSymbol) -> SomeSymbol
forall (s :: Symbol) r. SSymbol s -> (KnownSymbol s => r) -> r
withKnownSymbol SSymbol s
ss (forall (n :: Symbol). KnownSymbol n => Proxy n -> SomeSymbol
SomeSymbol @s Proxy s
forall {k} (t :: k). Proxy t
Proxy))
instance Eq SomeSymbol where
SomeSymbol Proxy n
x == :: SomeSymbol -> SomeSymbol -> Bool
== SomeSymbol Proxy n
y = Proxy n -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal Proxy n
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy n -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal Proxy n
y
instance Ord SomeSymbol where
compare :: SomeSymbol -> SomeSymbol -> Ordering
compare (SomeSymbol Proxy n
x) (SomeSymbol Proxy n
y) = String -> String -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Proxy n -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal Proxy n
x) (Proxy n -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal Proxy n
y)
instance Show SomeSymbol where
showsPrec :: Int -> SomeSymbol -> ShowS
showsPrec Int
p (SomeSymbol Proxy n
x) = Int -> String -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Proxy n -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal Proxy n
x)
instance Read SomeSymbol where
readsPrec :: Int -> ReadS SomeSymbol
readsPrec Int
p String
xs = [ (String -> SomeSymbol
someSymbolVal String
a, String
ys) | (String
a,String
ys) <- Int -> ReadS String
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
xs ]
someCharVal :: Char -> SomeChar
someCharVal :: Char -> SomeChar
someCharVal Char
c = Char -> (forall (c :: Char). SChar c -> SomeChar) -> SomeChar
forall r. Char -> (forall (c :: Char). SChar c -> r) -> r
withSomeSChar Char
c (\(SChar c
sc :: SChar c) ->
SChar c -> (KnownChar c => SomeChar) -> SomeChar
forall (c :: Char) r. SChar c -> (KnownChar c => r) -> r
withKnownChar SChar c
sc (forall (n :: Char). KnownChar n => Proxy n -> SomeChar
SomeChar @c Proxy c
forall {k} (t :: k). Proxy t
Proxy))
instance Eq SomeChar where
SomeChar Proxy n
x == :: SomeChar -> SomeChar -> Bool
== SomeChar Proxy n
y = Proxy n -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal Proxy n
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Proxy n -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal Proxy n
y
instance Ord SomeChar where
compare :: SomeChar -> SomeChar -> Ordering
compare (SomeChar Proxy n
x) (SomeChar Proxy n
y) = Char -> Char -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Proxy n -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal Proxy n
x) (Proxy n -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal Proxy n
y)
instance Show SomeChar where
showsPrec :: Int -> SomeChar -> ShowS
showsPrec Int
p (SomeChar Proxy n
x) = Int -> Char -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (Proxy n -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal Proxy n
x)
instance Read SomeChar where
readsPrec :: Int -> ReadS SomeChar
readsPrec Int
p String
xs = [ (Char -> SomeChar
someCharVal Char
a, String
ys) | (Char
a,String
ys) <- Int -> ReadS Char
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
xs ]
type family AppendSymbol (m ::Symbol) (n :: Symbol) :: Symbol
type family ConsSymbol (a :: Char) (b :: Symbol) :: Symbol
type family UnconsSymbol (a :: Symbol) :: Maybe (Char, Symbol)
type family CharToNat (c :: Char) :: N.Nat
type family NatToChar (n :: N.Nat) :: Char
sameSymbol :: forall a b proxy1 proxy2.
(KnownSymbol a, KnownSymbol b) =>
proxy1 a -> proxy2 b -> Maybe (a :~: b)
sameSymbol :: forall (a :: Symbol) (b :: Symbol) (proxy1 :: Symbol -> *)
(proxy2 :: Symbol -> *).
(KnownSymbol a, KnownSymbol b) =>
proxy1 a -> proxy2 b -> Maybe (a :~: b)
sameSymbol proxy1 a
_ proxy2 b
_ = SSymbol a -> SSymbol b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Maybe (a :~: b)
testEquality (forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing @a) (forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing @b)
decideSymbol :: forall a b proxy1 proxy2.
(KnownSymbol a, KnownSymbol b) =>
proxy1 a -> proxy2 b -> Either (a :~: b -> Void) (a :~: b)
decideSymbol :: forall (a :: Symbol) (b :: Symbol) (proxy1 :: Symbol -> *)
(proxy2 :: Symbol -> *).
(KnownSymbol a, KnownSymbol b) =>
proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b)
decideSymbol proxy1 a
_ proxy2 b
_ = SSymbol a -> SSymbol b -> Either ((a :~: b) -> Void) (a :~: b)
forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Either ((a :~: b) -> Void) (a :~: b)
decSymbol (forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing @a) (forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing @b)
decSymbol :: SSymbol a -> SSymbol b -> Either (a :~: b -> Void) (a :~: b)
decSymbol :: forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Either ((a :~: b) -> Void) (a :~: b)
decSymbol (UnsafeSSymbol String
x) (UnsafeSSymbol String
y)
| String
x String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
y = (a :~: b) -> Either ((a :~: b) -> Void) (a :~: b)
forall a b. b -> Either a b
Right ((Any :~: Any) -> a :~: b
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl)
| Bool
otherwise = ((a :~: b) -> Void) -> Either ((a :~: b) -> Void) (a :~: b)
forall a b. a -> Either a b
Left (\a :~: b
Refl -> String -> Void
forall a. String -> a
errorWithoutStackTrace (String
"decideSymbol: Impossible equality proof " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" :~: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
y))
sameChar :: forall a b proxy1 proxy2.
(KnownChar a, KnownChar b) =>
proxy1 a -> proxy2 b -> Maybe (a :~: b)
sameChar :: forall (a :: Char) (b :: Char) (proxy1 :: Char -> *)
(proxy2 :: Char -> *).
(KnownChar a, KnownChar b) =>
proxy1 a -> proxy2 b -> Maybe (a :~: b)
sameChar proxy1 a
_ proxy2 b
_ = SChar a -> SChar b -> Maybe (a :~: b)
forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality (forall (n :: Char). KnownChar n => SChar n
charSing @a) (forall (n :: Char). KnownChar n => SChar n
charSing @b)
decideChar :: forall a b proxy1 proxy2.
(KnownChar a, KnownChar b) =>
proxy1 a -> proxy2 b -> Either (a :~: b -> Void) (a :~: b)
decideChar :: forall (a :: Char) (b :: Char) (proxy1 :: Char -> *)
(proxy2 :: Char -> *).
(KnownChar a, KnownChar b) =>
proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b)
decideChar proxy1 a
_ proxy2 b
_ = SChar a -> SChar b -> Either ((a :~: b) -> Void) (a :~: b)
forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Either ((a :~: b) -> Void) (a :~: b)
decChar (forall (n :: Char). KnownChar n => SChar n
charSing @a) (forall (n :: Char). KnownChar n => SChar n
charSing @b)
decChar :: SChar a -> SChar b -> Either (a :~: b -> Void) (a :~: b)
decChar :: forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Either ((a :~: b) -> Void) (a :~: b)
decChar (UnsafeSChar Char
x) (UnsafeSChar Char
y)
| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
y = (a :~: b) -> Either ((a :~: b) -> Void) (a :~: b)
forall a b. b -> Either a b
Right ((Any :~: Any) -> a :~: b
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl)
| Bool
otherwise = ((a :~: b) -> Void) -> Either ((a :~: b) -> Void) (a :~: b)
forall a b. a -> Either a b
Left (\a :~: b
Refl -> String -> Void
forall a. String -> a
errorWithoutStackTrace (String
"decideChar: Impossible equality proof " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char -> String
forall a. Show a => a -> String
show Char
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" :~: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char -> String
forall a. Show a => a -> String
show Char
y))
cmpSymbol :: forall a b proxy1 proxy2. (KnownSymbol a, KnownSymbol b)
=> proxy1 a -> proxy2 b -> OrderingI a b
cmpSymbol :: forall (a :: Symbol) (b :: Symbol) (proxy1 :: Symbol -> *)
(proxy2 :: Symbol -> *).
(KnownSymbol a, KnownSymbol b) =>
proxy1 a -> proxy2 b -> OrderingI a b
cmpSymbol proxy1 a
x proxy2 b
y = case String -> String -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (proxy1 a -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal proxy1 a
x) (proxy2 b -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal proxy2 b
y) of
Ordering
EQ -> case (Any :~: Any, Any :~: Any) -> (CmpSymbol a b :~: 'EQ, a :~: b)
forall a b. a -> b
unsafeCoerce (Any :~: Any
forall {k} (a :: k). a :~: a
Refl, Any :~: Any
forall {k} (a :: k). a :~: a
Refl) :: (CmpSymbol a b :~: 'EQ, a :~: b) of
(CmpSymbol a b :~: 'EQ
Refl, a :~: b
Refl) -> OrderingI a a
OrderingI a b
forall {k} (a :: k). (Compare a a ~ 'EQ) => OrderingI a a
EQI
Ordering
LT -> case (Any :~: Any) -> CmpSymbol a b :~: 'LT
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl :: (CmpSymbol a b :~: 'LT) of
CmpSymbol a b :~: 'LT
Refl -> OrderingI a b
forall {k} (a :: k) (b :: k). (Compare a b ~ 'LT) => OrderingI a b
LTI
Ordering
GT -> case (Any :~: Any) -> CmpSymbol a b :~: 'GT
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl :: (CmpSymbol a b :~: 'GT) of
CmpSymbol a b :~: 'GT
Refl -> OrderingI a b
forall {k} (a :: k) (b :: k). (Compare a b ~ 'GT) => OrderingI a b
GTI
cmpChar :: forall a b proxy1 proxy2. (KnownChar a, KnownChar b)
=> proxy1 a -> proxy2 b -> OrderingI a b
cmpChar :: forall (a :: Char) (b :: Char) (proxy1 :: Char -> *)
(proxy2 :: Char -> *).
(KnownChar a, KnownChar b) =>
proxy1 a -> proxy2 b -> OrderingI a b
cmpChar proxy1 a
x proxy2 b
y = case Char -> Char -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (proxy1 a -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal proxy1 a
x) (proxy2 b -> Char
forall (n :: Char) (proxy :: Char -> *).
KnownChar n =>
proxy n -> Char
charVal proxy2 b
y) of
Ordering
EQ -> case (Any :~: Any, Any :~: Any) -> (CmpChar a b :~: 'EQ, a :~: b)
forall a b. a -> b
unsafeCoerce (Any :~: Any
forall {k} (a :: k). a :~: a
Refl, Any :~: Any
forall {k} (a :: k). a :~: a
Refl) :: (CmpChar a b :~: 'EQ, a :~: b) of
(CmpChar a b :~: 'EQ
Refl, a :~: b
Refl) -> OrderingI a a
OrderingI a b
forall {k} (a :: k). (Compare a a ~ 'EQ) => OrderingI a a
EQI
Ordering
LT -> case (Any :~: Any) -> CmpChar a b :~: 'LT
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl :: (CmpChar a b :~: 'LT) of
CmpChar a b :~: 'LT
Refl -> OrderingI a b
forall {k} (a :: k) (b :: k). (Compare a b ~ 'LT) => OrderingI a b
LTI
Ordering
GT -> case (Any :~: Any) -> CmpChar a b :~: 'GT
forall a b. a -> b
unsafeCoerce Any :~: Any
forall {k} (a :: k). a :~: a
Refl :: (CmpChar a b :~: 'GT) of
CmpChar a b :~: 'GT
Refl -> OrderingI a b
forall {k} (a :: k) (b :: k). (Compare a b ~ 'GT) => OrderingI a b
GTI
fromSNat :: N.SNat n -> Integer
fromSNat :: forall (n :: Natural). SNat n -> Integer
fromSNat SNat n
sn = Natural -> Integer
forall a. Integral a => a -> Integer
toInteger (SNat n -> Natural
forall (n :: Natural). SNat n -> Natural
N.fromSNat SNat n
sn)
withSomeSNat :: forall rep (r :: TYPE rep).
Integer -> (forall n. Maybe (N.SNat n) -> r) -> r
withSomeSNat :: forall r.
Integer -> (forall (n :: Natural). Maybe (SNat n) -> r) -> r
withSomeSNat Integer
n forall (n :: Natural). Maybe (SNat n) -> r
k
| Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0 = Natural -> (forall (n :: Natural). SNat n -> r) -> r
forall r. Natural -> (forall (n :: Natural). SNat n -> r) -> r
N.withSomeSNat (Integer -> Natural
forall a. Num a => Integer -> a
fromInteger Integer
n) (\SNat n
sn -> Maybe (SNat n) -> r
forall (n :: Natural). Maybe (SNat n) -> r
k (SNat n -> Maybe (SNat n)
forall a. a -> Maybe a
Just SNat n
sn))
| Bool
otherwise = Maybe (SNat Any) -> r
forall (n :: Natural). Maybe (SNat n) -> r
k Maybe (SNat Any)
forall a. Maybe a
Nothing
newtype SSymbol (s :: Symbol) = UnsafeSSymbol String
type role SSymbol nominal
pattern SSymbol :: forall s. () => KnownSymbol s => SSymbol s
pattern $mSSymbol :: forall {r} {s :: Symbol}.
SSymbol s -> (KnownSymbol s => r) -> ((# #) -> r) -> r
$bSSymbol :: forall (n :: Symbol). KnownSymbol n => SSymbol n
SSymbol <- (knownSymbolInstance -> KnownSymbolInstance)
where SSymbol = SSymbol s
forall (n :: Symbol). KnownSymbol n => SSymbol n
symbolSing
{-# COMPLETE SSymbol #-}
data KnownSymbolInstance (s :: Symbol) where
KnownSymbolInstance :: KnownSymbol s => KnownSymbolInstance s
knownSymbolInstance :: SSymbol s -> KnownSymbolInstance s
knownSymbolInstance :: forall (s :: Symbol). SSymbol s -> KnownSymbolInstance s
knownSymbolInstance SSymbol s
ss = SSymbol s
-> (KnownSymbol s => KnownSymbolInstance s)
-> KnownSymbolInstance s
forall (s :: Symbol) r. SSymbol s -> (KnownSymbol s => r) -> r
withKnownSymbol SSymbol s
ss KnownSymbolInstance s
KnownSymbol s => KnownSymbolInstance s
forall (s :: Symbol). KnownSymbol s => KnownSymbolInstance s
KnownSymbolInstance
instance Eq (SSymbol s) where
SSymbol s
_ == :: SSymbol s -> SSymbol s -> Bool
== SSymbol s
_ = Bool
True
instance Ord (SSymbol s) where
compare :: SSymbol s -> SSymbol s -> Ordering
compare SSymbol s
_ SSymbol s
_ = Ordering
EQ
instance Show (SSymbol s) where
showsPrec :: Int -> SSymbol s -> ShowS
showsPrec Int
p (UnsafeSSymbol String
s)
= Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec)
( String -> ShowS
showString String
"SSymbol @"
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
appPrec1 String
s
)
instance TestEquality SSymbol where
testEquality :: forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Maybe (a :~: b)
testEquality SSymbol a
a SSymbol b
b = case SSymbol a -> SSymbol b -> Either ((a :~: b) -> Void) (a :~: b)
forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Either ((a :~: b) -> Void) (a :~: b)
decSymbol SSymbol a
a SSymbol b
b of
Right a :~: b
p -> (a :~: b) -> Maybe (a :~: b)
forall a. a -> Maybe a
Just a :~: b
p
Left (a :~: b) -> Void
_ -> Maybe (a :~: b)
forall a. Maybe a
Nothing
instance TestCoercion SSymbol where
testCoercion :: forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Maybe (Coercion a b)
testCoercion SSymbol a
x SSymbol b
y = ((a :~: b) -> Coercion a b)
-> Maybe (a :~: b) -> Maybe (Coercion a b)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a :~: b
Refl -> Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion) (SSymbol a -> SSymbol b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
forall (a :: Symbol) (b :: Symbol).
SSymbol a -> SSymbol b -> Maybe (a :~: b)
testEquality SSymbol a
x SSymbol b
y)
fromSSymbol :: SSymbol s -> String
fromSSymbol :: forall (s :: Symbol). SSymbol s -> String
fromSSymbol (UnsafeSSymbol String
s) = String
s
withKnownSymbol :: forall s rep (r :: TYPE rep).
SSymbol s -> (KnownSymbol s => r) -> r
withKnownSymbol :: forall (s :: Symbol) r. SSymbol s -> (KnownSymbol s => r) -> r
withKnownSymbol = forall (cls :: Constraint) meth r.
WithDict cls meth =>
meth -> (cls => r) -> r
withDict @(KnownSymbol s)
withSomeSSymbol :: forall rep (r :: TYPE rep).
String -> (forall s. SSymbol s -> r) -> r
withSomeSSymbol :: forall r. String -> (forall (s :: Symbol). SSymbol s -> r) -> r
withSomeSSymbol String
s forall (s :: Symbol). SSymbol s -> r
k = SSymbol Any -> r
forall (s :: Symbol). SSymbol s -> r
k (String -> SSymbol Any
forall (s :: Symbol). String -> SSymbol s
UnsafeSSymbol String
s)
{-# NOINLINE withSomeSSymbol #-}
newtype SChar (s :: Char) = UnsafeSChar Char
type role SChar nominal
pattern SChar :: forall c. () => KnownChar c => SChar c
pattern $mSChar :: forall {r} {c :: Char}.
SChar c -> (KnownChar c => r) -> ((# #) -> r) -> r
$bSChar :: forall (n :: Char). KnownChar n => SChar n
SChar <- (knownCharInstance -> KnownCharInstance)
where SChar = SChar c
forall (n :: Char). KnownChar n => SChar n
charSing
{-# COMPLETE SChar #-}
data KnownCharInstance (n :: Char) where
KnownCharInstance :: KnownChar c => KnownCharInstance c
knownCharInstance :: SChar c -> KnownCharInstance c
knownCharInstance :: forall (c :: Char). SChar c -> KnownCharInstance c
knownCharInstance SChar c
sc = SChar c
-> (KnownChar c => KnownCharInstance c) -> KnownCharInstance c
forall (c :: Char) r. SChar c -> (KnownChar c => r) -> r
withKnownChar SChar c
sc KnownCharInstance c
KnownChar c => KnownCharInstance c
forall (c :: Char). KnownChar c => KnownCharInstance c
KnownCharInstance
instance Eq (SChar c) where
SChar c
_ == :: SChar c -> SChar c -> Bool
== SChar c
_ = Bool
True
instance Ord (SChar c) where
compare :: SChar c -> SChar c -> Ordering
compare SChar c
_ SChar c
_ = Ordering
EQ
instance Show (SChar c) where
showsPrec :: Int -> SChar c -> ShowS
showsPrec Int
p (UnsafeSChar Char
c)
= Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec)
( String -> ShowS
showString String
"SChar @"
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Char -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
appPrec1 Char
c
)
instance TestEquality SChar where
testEquality :: forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Maybe (a :~: b)
testEquality SChar a
a SChar b
b = case SChar a -> SChar b -> Either ((a :~: b) -> Void) (a :~: b)
forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Either ((a :~: b) -> Void) (a :~: b)
decChar SChar a
a SChar b
b of
Right a :~: b
p -> (a :~: b) -> Maybe (a :~: b)
forall a. a -> Maybe a
Just a :~: b
p
Left (a :~: b) -> Void
_ -> Maybe (a :~: b)
forall a. Maybe a
Nothing
instance TestCoercion SChar where
testCoercion :: forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Maybe (Coercion a b)
testCoercion SChar a
x SChar b
y = ((a :~: b) -> Coercion a b)
-> Maybe (a :~: b) -> Maybe (Coercion a b)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a :~: b
Refl -> Coercion a b
forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion) (SChar a -> SChar b -> Maybe (a :~: b)
forall (a :: Char) (b :: Char).
SChar a -> SChar b -> Maybe (a :~: b)
forall {k} (f :: k -> *) (a :: k) (b :: k).
TestEquality f =>
f a -> f b -> Maybe (a :~: b)
testEquality SChar a
x SChar b
y)
fromSChar :: SChar c -> Char
fromSChar :: forall (c :: Char). SChar c -> Char
fromSChar (UnsafeSChar Char
c) = Char
c
withKnownChar :: forall c rep (r :: TYPE rep).
SChar c -> (KnownChar c => r) -> r
withKnownChar :: forall (c :: Char) r. SChar c -> (KnownChar c => r) -> r
withKnownChar = forall (cls :: Constraint) meth r.
WithDict cls meth =>
meth -> (cls => r) -> r
withDict @(KnownChar c)
withSomeSChar :: forall rep (r :: TYPE rep).
Char -> (forall c. SChar c -> r) -> r
withSomeSChar :: forall r. Char -> (forall (c :: Char). SChar c -> r) -> r
withSomeSChar Char
c forall (c :: Char). SChar c -> r
k = SChar Any -> r
forall (c :: Char). SChar c -> r
k (Char -> SChar Any
forall (s :: Char). Char -> SChar s
UnsafeSChar Char
c)
{-# NOINLINE withSomeSChar #-}