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, LengthSymbol prefix < 64, IsLowerSymbol prefix ~ 'True)
- class ToPrefix a where
- type PrefixSymbol a :: Symbol
- type family LengthSymbol (prefix :: Symbol) :: Nat where ...
- type family IsLowerSymbol (prefix :: Symbol) :: Bool where ...
- type family IsLowerChar (ch :: Char) :: Bool where ...
- type family LSUH (uncons :: Maybe (Char, Symbol)) :: Nat where ...
- type family ILSUH (uncons :: Maybe (Char, Symbol)) :: Bool where ...
Prefix
type ValidPrefix prefix = (KnownSymbol prefix, LengthSymbol prefix < 64, IsLowerSymbol prefix ~ 'True) 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
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"
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"
type PrefixSymbol a :: Symbol Source #
Instances
ToPrefix (a :: Symbol) Source # | The |
Defined in Data.KindID.Class type PrefixSymbol a :: Symbol Source # |
Helpers
type family LengthSymbol (prefix :: Symbol) :: Nat where ... Source #
LengthSymbol prefix = LSUH (UnconsSymbol prefix) |
type family IsLowerSymbol (prefix :: Symbol) :: Bool where ... Source #
Is a Symbol
lower case?
IsLowerSymbol prefix = ILSUH (UnconsSymbol prefix) |