| License | MIT |
|---|---|
| Maintainer | mmzk1526@outlook.com |
| Portability | GHC |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Data.KindID.Class
Description
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 Symbols.
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 KindIDs, e.g.
do userID <- genKindID @'User -- Same as genKindID @"user" postID <- genKindID @'Post -- Same as genKindID @"post" commentID <- genKindID @'Comment -- Same as genKindID @"comment"
Associated Types
type PrefixSymbol a :: Symbol Source #
Instances
| ToPrefix (a :: Symbol) Source # | The |
Defined in Data.KindID.Class Associated Types type PrefixSymbol a :: Symbol Source # | |
Helpers
type family LengthSymbol (prefix :: Symbol) :: Nat where ... Source #
Equations
| LengthSymbol prefix = LSUH (UnconsSymbol prefix) |
type family IsLowerSymbol (prefix :: Symbol) :: Bool where ... Source #
Is a Symbol lower case?
Equations
| IsLowerSymbol prefix = ILSUH (UnconsSymbol prefix) |