class TypeName (a ∷ Type) (name ∷ Symbol) | a → name, name → a
For all types there is an instance of TypeName which bijectively maps types to their fully-qualified name.
A higher-order example is:
TypeName (Maybe Int) "(Data.Maybe.Maybe Prim.Int)"
Two reasons I know of to have this.
- Dynamic.
foreign import data Any ∷ Type
data Dynamic = Dynamic String Any
toDynamic ∷ ∀ a name. IsSymbol name ⇒ TypeName a name ⇒ a → Dynamic
toDynamic x = Dynamic (reflectSymbol (SProxy∷_ name)) (unsafeCoerce x)
fromDynamic ∷ ∀ a name. IsSymbol name ⇒ TypeName a name ⇒ Dynamic → Maybe a
fromDynamic (Dynamic name x)
| name == reflectSymbol (SProxy∷_ name) = Just (unsafeCoerce x)
| otherwise = Nothing
- Efficient type-level Type sets (because rows already have bespoke solvers). Every label is the type name of its type. For example:
( "(Data.Maybe.Maybe Prim.Int)" ∷ Maybe Int, "Prim.Int" ∷ Int )
For all types there is an instance of TypeName which bijectively maps types to their fully-qualified name.
A higher-order example is:
Two reasons I know of to have this.