parameterized-utils-2.1.11.0: Classes and data structures for working with data-kind indexed types

Copyright | (c) Galois Inc 2014-2019
Maintainer | Joe Hendrix <jhendrix@galois.com>
Safe Haskell | Trustworthy
Language | Haskell2010

Data.Parameterized.SymbolRepr

Contents

- SymbolRepr
- Re-exports

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 :: forall (s :: Symbol). KnownSymbol s => SymbolRepr s
- someSymbol :: Text -> Some SymbolRepr
- data SomeSym (c :: Symbol -> Type) = 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

Instances details

TestEquality SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods testEquality :: forall (a :: Symbol) (b :: Symbol). SymbolRepr a -> SymbolRepr b -> Maybe (a :~: b) Source #
EqF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods eqF :: forall (a :: Symbol). SymbolRepr a -> SymbolRepr a -> Bool Source #
HashableF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods hashWithSaltF :: forall (tp :: Symbol). Int -> SymbolRepr tp -> Int Source # hashF :: forall (tp :: Symbol). SymbolRepr tp -> Int Source #
OrdF SymbolRepr Source # |

Instance details

Defined in Data.Parameterized.SymbolRepr

Methods

compareF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> OrderingF x y Source #

leqF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

ltF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

geqF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

gtF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

ShowF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods withShow :: forall p q (tp :: Symbol) a. p SymbolRepr -> q tp -> (Show (SymbolRepr tp) => a) -> a Source # showF :: forall (tp :: Symbol). SymbolRepr tp -> String Source # showsPrecF :: forall (tp :: Symbol). Int -> SymbolRepr tp -> String -> String Source #
IsRepr SymbolRepr Source # |
Instance details Defined in Data.Parameterized.WithRepr Methods withRepr :: forall (a :: Symbol) r. SymbolRepr a -> (KnownRepr SymbolRepr a => r) -> r Source #
KnownSymbol s => KnownRepr SymbolRepr (s :: Symbol) Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods knownRepr :: SymbolRepr s Source #
Show (SymbolRepr nm) Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods showsPrec :: Int -> SymbolRepr nm -> ShowS Source # show :: SymbolRepr nm -> String Source # showList :: [SymbolRepr nm] -> ShowS Source #
Eq (SymbolRepr x) Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods (==) :: SymbolRepr x -> SymbolRepr x -> Bool Source # (/=) :: SymbolRepr x -> SymbolRepr x -> Bool Source #
Ord (SymbolRepr x) Source # |

Instance details

Defined in Data.Parameterized.SymbolRepr

Methods

compare :: SymbolRepr x -> SymbolRepr x -> Ordering Source #

(<) :: SymbolRepr x -> SymbolRepr x -> Bool Source #

(<=) :: SymbolRepr x -> SymbolRepr x -> Bool Source #

(>) :: SymbolRepr x -> SymbolRepr x -> Bool Source #

(>=) :: SymbolRepr x -> SymbolRepr x -> Bool Source #

max :: SymbolRepr x -> SymbolRepr x -> SymbolRepr x Source #

min :: SymbolRepr x -> SymbolRepr x -> SymbolRepr x Source #

Hashable (SymbolRepr nm) Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods hashWithSalt :: Int -> SymbolRepr nm -> Int Source # hash :: SymbolRepr nm -> Int Source #

symbolRepr :: SymbolRepr nm -> Text Source #

The underlying text representation of the symbol

knownSymbol :: forall (s :: Symbol). 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

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

data Symbol Source #

(Kind) This is the kind of type-level symbols.

#### Instances

Instances details

SingKind Symbol | Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Generics

Associated Types

type DemoteRep Symbol |
Instance details Defined in GHC.Internal.Generics type DemoteRep Symbol = String

Methods

fromSing :: forall (a :: Symbol). Sing a -> DemoteRep Symbol

TestCoercion SSymbol | Since: base-4.18.0.0
Instance details Defined in GHC.Internal.TypeLits Methods testCoercion :: forall (a :: Symbol) (b :: Symbol). SSymbol a -> SSymbol b -> Maybe (Coercion a b) Source #
TestEquality SSymbol | Since: base-4.18.0.0
Instance details Defined in GHC.Internal.TypeLits Methods testEquality :: forall (a :: Symbol) (b :: Symbol). SSymbol a -> SSymbol b -> Maybe (a :~: b) Source #
TestEquality SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods testEquality :: forall (a :: Symbol) (b :: Symbol). SymbolRepr a -> SymbolRepr b -> Maybe (a :~: b) Source #
KnownSymbol a => SingI (a :: Symbol) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods sing :: Sing a
EqF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods eqF :: forall (a :: Symbol). SymbolRepr a -> SymbolRepr a -> Bool Source #
HashableF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods hashWithSaltF :: forall (tp :: Symbol). Int -> SymbolRepr tp -> Int Source # hashF :: forall (tp :: Symbol). SymbolRepr tp -> Int Source #
OrdF SymbolRepr Source # |

Instance details

Defined in Data.Parameterized.SymbolRepr

Methods

compareF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> OrderingF x y Source #

leqF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

ltF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

geqF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

gtF :: forall (x :: Symbol) (y :: Symbol). SymbolRepr x -> SymbolRepr y -> Bool Source #

ShowF SymbolRepr Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods withShow :: forall p q (tp :: Symbol) a. p SymbolRepr -> q tp -> (Show (SymbolRepr tp) => a) -> a Source # showF :: forall (tp :: Symbol). SymbolRepr tp -> String Source # showsPrecF :: forall (tp :: Symbol). Int -> SymbolRepr tp -> String -> String Source #
IsRepr SymbolRepr Source # |
Instance details Defined in Data.Parameterized.WithRepr Methods withRepr :: forall (a :: Symbol) r. SymbolRepr a -> (KnownRepr SymbolRepr a => r) -> r Source #
KnownSymbol s => KnownRepr SymbolRepr (s :: Symbol) Source # |
Instance details Defined in Data.Parameterized.SymbolRepr Methods knownRepr :: SymbolRepr s Source #
KnownSymbol n => Reifies (n :: Symbol) String |
Instance details Defined in Data.Reflection Methods reflect :: proxy n -> String
type DemoteRep Symbol |
Instance details Defined in GHC.Internal.Generics type DemoteRep Symbol = String
data Sing (s :: Symbol) |

Instance details

Defined in GHC.Internal.Generics

data Sing (s :: Symbol) where

- SSym :: forall (s :: Symbol). KnownSymbol s => Sing s

type Compare (a :: Symbol) (b :: Symbol) |
Instance details Defined in GHC.Internal.Data.Type.Ord type Compare (a :: Symbol) (b :: Symbol) = CmpSymbol a b

class KnownSymbol (n :: Symbol) Source #

This class gives the string associated with a type-level symbol. There are instances of the class for every concrete literal: "hello", etc.

Since: base-4.7.0.0

Minimal complete definition

symbolSing