License | MIT |
---|---|
Maintainer | mmzk1526@outlook.com |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module contains the type-level mechanisms that are used to define
custom KindID
-ish identifier types.
Synopsis
- type ValidPrefix prefix = KnownSymbol prefix
- class ToPrefix a where
- type PrefixSymbol a :: Symbol
Prefix
type ValidPrefix prefix = KnownSymbol prefix Source #
A constraint for valid prefix Symbol
s.
A class that translates any kind to a Symbol
. It is used to translate
custom data kinds to a Symbol
so that they can be used as
KindID
prefixes.
For example, suppose we have the following data structure that represents the prefixes we are going to use:
data Prefix = User | Post | Comment | SuperUser
Then we can make it an instance of ToPrefix
like this:
instance ToPrefix 'User where type PrefixSymbol 'User = "user" instance ToPrefix 'Post where type PrefixSymbol 'Post = "post" instance ToPrefix 'Comment where type PrefixSymbol 'Comment = "comment" instance ToPrefix 'SuperUser where type PrefixSymbol 'SuperUser = "super_user"
Now we can use Prefix as a prefix for KindID
s, e.g.
do userID <- genKindID @'User -- Same as genKindID @"user" postID <- genKindID @'Post -- Same as genKindID @"post" commentID <- genKindID @'Comment -- Same as genKindID @"comment" suID <- genKindID @'SuperUser -- Same as genKindID @"super_user"
type PrefixSymbol a :: Symbol Source #
The associated type family that converts a
into a Symbol
.
Instances
ToPrefix (s :: Symbol) Source # | The |
Defined in Data.KindID.Class type PrefixSymbol s :: Symbol Source # |