Copyright | (c) Galois Inc 2014-2019 |
---|---|
Maintainer | Joe Hendrix <jhendrix@galois.com> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Data.Parameterized.SymbolRepr
Contents
Description
This defines a type family SymbolRepr
for representing a type-level string
(AKA symbol) at runtime. This can be used to branch on a type-level value.
The TestEquality
and OrdF
instances for SymbolRepr
are implemented using
unsafeCoerce
. This should be typesafe because we maintain the invariant
that the string value contained in a SymbolRepr value matches its static type.
At the type level, symbols have very few operations, so SymbolRepr correspondingly has very few functions that manipulate them.
Synopsis
- data SymbolRepr (nm :: Symbol)
- symbolRepr :: SymbolRepr nm -> Text
- knownSymbol :: KnownSymbol s => SymbolRepr s
- someSymbol :: Text -> Some SymbolRepr
- data SomeSym (c :: Symbol -> Type) = forall (s :: Symbol).KnownSymbol s => SomeSym (c s)
- viewSomeSym :: (forall (s :: Symbol). KnownSymbol s => c s -> r) -> SomeSym c -> r
- data Symbol
- class KnownSymbol (n :: Symbol)
SymbolRepr
data SymbolRepr (nm :: Symbol) Source #
A runtime representation of a GHC type-level symbol.
Instances
symbolRepr :: SymbolRepr nm -> Text Source #
The underlying text representation of the symbol
knownSymbol :: KnownSymbol s => SymbolRepr s Source #
Generate a value representative for the type level symbol.
someSymbol :: Text -> Some SymbolRepr Source #
Generate a symbol representative at runtime. The type-level
symbol will be abstract, as it is hidden by the Some
constructor.
data SomeSym (c :: Symbol -> Type) Source #
The SomeSym hides a Symbol parameter but preserves a KnownSymbol constraint on the hidden parameter.
Constructors
forall (s :: Symbol).KnownSymbol s => SomeSym (c s) |
viewSomeSym :: (forall (s :: Symbol). KnownSymbol s => c s -> r) -> SomeSym c -> r Source #
Projects a value out of a SomeSym into a function, re-ifying the Symbol type parameter to the called function, along with the KnownSymbol constraint on that Symbol value.
Re-exports
Instances
SingKind Symbol | |
Defined in GHC.Generics Associated Types type DemoteRep Symbol | |
TestEquality SymbolRepr Source # | |
Defined in Data.Parameterized.SymbolRepr Methods testEquality :: forall (a :: k) (b :: k). SymbolRepr a -> SymbolRepr b -> Maybe (a :~: b) # | |
KnownSymbol a => SingI (a :: Symbol) | |
Defined in GHC.Generics Methods sing :: Sing a | |
HashableF SymbolRepr Source # | |
Defined in Data.Parameterized.SymbolRepr Methods hashWithSaltF :: forall (tp :: k). Int -> SymbolRepr tp -> Int Source # hashF :: forall (tp :: k). SymbolRepr tp -> Int Source # | |
OrdF SymbolRepr Source # | |
Defined in Data.Parameterized.SymbolRepr Methods compareF :: forall (x :: k) (y :: k). SymbolRepr x -> SymbolRepr y -> OrderingF x y Source # leqF :: forall (x :: k) (y :: k). SymbolRepr x -> SymbolRepr y -> Bool Source # ltF :: forall (x :: k) (y :: k). SymbolRepr x -> SymbolRepr y -> Bool Source # geqF :: forall (x :: k) (y :: k). SymbolRepr x -> SymbolRepr y -> Bool Source # gtF :: forall (x :: k) (y :: k). SymbolRepr x -> SymbolRepr y -> Bool Source # | |
ShowF SymbolRepr Source # | |
Defined in Data.Parameterized.SymbolRepr Methods withShow :: forall p q (tp :: k) a. p SymbolRepr -> q tp -> (Show (SymbolRepr tp) => a) -> a Source # showF :: forall (tp :: k). SymbolRepr tp -> String Source # showsPrecF :: forall (tp :: k). Int -> SymbolRepr tp -> String -> String Source # | |
IsRepr SymbolRepr Source # | |
Defined in Data.Parameterized.WithRepr Methods withRepr :: forall (a :: k) r. SymbolRepr a -> (KnownRepr SymbolRepr a => r) -> r Source # | |
KnownSymbol s => KnownRepr SymbolRepr (s :: Symbol) Source # | |
Defined in Data.Parameterized.SymbolRepr Methods knownRepr :: SymbolRepr s Source # | |
KnownSymbol n => Reifies (n :: Symbol) String | |
Defined in Data.Reflection | |
type DemoteRep Symbol | |
Defined in GHC.Generics type DemoteRep Symbol = String | |
data Sing (s :: Symbol) | |
Defined in GHC.Generics | |
type Compare (a :: Symbol) (b :: Symbol) | |
Defined in Data.Type.Ord |
class KnownSymbol (n :: Symbol) #
Minimal complete definition
symbolSing